我目前正在尝试使用重定向
@H_403_1@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’的问题.我可以创建一个论坛并保存它,但当我尝试重定向时,我有这个错误
@H_403_1@Trying to get property of non-object而users.courses.forums.index是我的URI与Action ForumController @ index的名称.最后一个方法需要2个参数($username,$courseid).像这样
@H_403_1@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()并将变量作为数组传递?
像这样的东西应该工作……
@H_403_1@return Redirect::route('users.courses.forums.index',array(Auth::user()->username,$course->id));