加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – laravel 4重定向到2个参数的路由

发布时间:2020-12-14 19:56:05 所属栏目:大数据 来源:网络整理
导读:我目前正在尝试使用重定向 public function store($username,$courseId){ if (Auth::user()-username == $username Auth::user()-courses()-where('id','=',$courseId)-first() != null){ $course = Course::find($courseId); $forum = new Forum(); $forum-
我目前正在尝试使用重定向
public function store($username,$courseId)
{       
        if (Auth::user()->username == $username && Auth::user()->courses()->where('id','=',$courseId)->first() != null){
        $course = Course::find($courseId);
        $forum = new Forum();
        $forum->description = Input::get('description');
        $forum->course_id   = Input::get('course_id');
        $forum->save();
        return Redirect::to(route('users.courses.forums.index',Auth::user()->username,$course->id));
        }
    return Redirect::to('/');
}

Redirect中的参数不起作用. Store是ForumController中的POST方法. Store收到的参数是正常的,因为我没有验证’if’的问题.我可以创建一个论坛并保存它,但当我尝试重定向时,我有这个错误

Trying to get property of non-object

而users.courses.forums.index是我的URI与Action ForumController @ index的名称.最后一个方法需要2个参数($username,$courseid).像这样

public function index($username,$courseId)
{       
        $course = Course::find($courseId);
        $forum = DB::table('forums')->where('course_id',$course->id)->get();
        return View::make('forums.index',compact('course','forum'));    
}
为什么不直接使用Redirect :: route()并将变量作为数组传递?

像这样的东西应该工作……

return Redirect::route('users.courses.forums.index',array(Auth::user()->username,$course->id));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读