I'm trying to create a url which reads www.localhost/forum/{slug}/thread={id} but im encountering problems. The {id} part is coming back as that is the thread id but the {slug} part i'm trying to retrieve through a foriegn key and get the issue.
Call to a member function forums() on null
here are my tables Forum: id, name, slug, timestamps Thread: id, name, forum_id, user_id
here is my relation on my thread model
public function forums(){
return $this->belongsTo('App\Forum');
}
and here is my code on my ThreadController
public function show($id, $slug)
{
//
$thread = Thread::find($id);
$thread->forums()->slug = $slug;
return view('forum.thread')->withThread($thread);
}
Any ideas on how i get the Forum's slug into the URL?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire