我目前正在尝试使用重定向
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));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。