I'm currently trying to implement redirects using
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('/'); }
Parameters in redirection do not work. The store is the POST method in ForumController. The parameters that are saved are "OK" because I have no problem checking if. I could create a forum and save it, but when I try to redirect, I have this error.
Trying to get property of non-object
And users.courses.forums.index is the name of my URI using the Action ForumController @index. This last method requires 2 parameters ($ username, $ courseid). Like this
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')); }
source share