dru5089 2016-10-06 20:17 采纳率: 0%
浏览 9
已采纳

无法通过控制器将参数传递给页面

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.

  • 写回答

1条回答 默认 最新

  • dongwo5449 2016-10-06 20:19
    关注
    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 '.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 目标跟踪,计算机视觉
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?
  • ¥200 C++表格文件处理-悬赏
  • ¥15 Windows Server2016本地登录失败
  • ¥15 复合卡卡号轨道写入芯片卡
  • ¥20 基于MATLAB的TDOA
  • ¥15 为啥输入字体突然变了
  • ¥20 已知坐标,换成MATLAB可以用的数据