Reputation: 39
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.
Upvotes: 2
Views: 2459
Reputation: 77
Use this below .htaccess
Options +ExecCGI
addhandler x-httpd-php5-cgi .php
Options -MultiViews
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Upvotes: 0
Reputation: 1246
I hope this will do the job
public function store(Request $request)
{
$error = false;
$errors = [];
foreach(Auth::user()->test as $data) {
if($request->name == $data->name) {
$error = true;
$errors['wrong'] = trans('settings.isset.name');
break;
}
else {
$this->validate($request, [
'name' => 'required',
]);
$name = Name::store($request);
}
}
if($error)
return back()->with($errors);
return back()->with('message', trans('settings.add.name'));
}
Upvotes: 1
Reputation: 377
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.
Upvotes: 3