I'm trying to display the latest Topic that is related to a Theme. I did this before and I tried the following code in the ThemesController (Index method, Sinse it's the homepage),
$topics = Theme::with('topic', 'lastTopic.user')->get();
$themes = Theme::all();
return view('themes.index')->with('themes', $themes)->with('topics', $topics);
And the method I'm calling is this.
public function lastTopic()
{
return $this->hasOne(Topic::class)->latest();
}
The method sits inside the Theme Model, It doesn't matter if i put the method in the Topic Model of the Theme Model, It still gives me the same error. So what is causing this issue? This is for my homepage so the route is this Route::get('/', 'ThemesController@index')->name('home');
. I know it is something I've done before but I can't figure it out. Thanks in advance
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire