rur2641 rur2641 - 1 month ago 7
PHP Question

Trouble passing arguments to a page through a controller

I am having trouble with a line in a controller:

public function checked(Request $request)
{
$user = DB::table('user2s')->where('name', $request->name)->first();
if (isset($user))
return redirect ('/’,['user'=>$request->name]);
else
return redirect('/');
}


The error is
"syntax error, unexpected 'user' (T_STRING)" line 29
.
The code before works because it recognizes when the passed name does not belong to a user in the users' table.

It works if written like:
return $user->id;
// or
$user->body
, the correct info is displayed.

It doesn't work with
redirect (compact('user'))
either.

Thank you.

Answer
public function checked(Request $request)
{
    $user = DB::table('user2s')->where('name', $request->name)->first();
    if (isset($user))
    return redirect ('/',['user'=>$request->name]);
    else
    return redirect('/');
}

Your error was caused in the first redirect. You have used instead of '.

Comments