无法通过控制器将参数传递给页面
问题描述:
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.
我在控制器中遇到一行问题: p>
公共功能检查(请求$请求)
{
$ user = DB :: table('user2s') - > where('name',$ request-> name) - > first(); \ n if(isset($ user))
返回重定向('/',['user'=> $ request-> name]);
else
返回redirect('/');
}
code> pre>
错误是“语法错误,意外'用户'(T_STRING)”第29行 code>。
之前的代码是因为它识别 当传递的名称不属于用户表中的用户时。 p>
如果编写如下: return $ user-> id; code> // 或 $ user-> body code>,显示正确的信息。 p>
它不能与重定向(compact('user'))一起使用 code>。 p>
谢谢。 p>
div>
答
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 '
.