tôi đang cố gắng để thực hiện đổi hướng sử dụnglaravel 4 Redirect để định tuyến với 2 thông số
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('/');
}
Các thông số trong Redirect không làm việc. Store là một phương thức POST trong ForumController. Các tham số mà Store nhận được là OK vì tôi không gặp vấn đề với việc xác nhận 'if'. Tôi đã có thể tạo ra một diễn đàn và lưu nó, nhưng khi tôi cố gắng để chuyển hướng tôi có lỗi này
Trying to get property of non-object
Và users.courses.forums.index là tên của URI của tôi với hành động ForumController @ index. Phương pháp cuối cùng này cần 2 tham số ($ username, $ courseid). Như thế này
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'));
}