I want to add a record to my DB using Laravel but after submitting a form I get a blank screen and no logs. Here's my code:
public function store(Request $request)
{
foreach(Auth::user()->test as $data) {
if($request->name == $data->name) {
return back()->with('wrong', trans('settings.isset.name'));
}
else {
$this->validate($request, [
'name' => 'required',
]);
$name = Name::store($request);
return back()->with('message', trans('settings.add.name'));
}
}
}
And there is, of course, a normal working form. Before when I didn't have foreach
it was working, but not it isn't.
I think that this can be caused when Auth::user()->test
is empty. Therefore code inside the foreach
loop is not executed and nothing is returned.
You could try putting the return
statement to the end of function.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments