Answer the question
In order to leave comments, you need to log in
Why is Laravel not displaying a post via BelongsTo()?
Good afternoon. I can't figure out relationships in Laravel.
Unable to select a record from the posts.slug column from the posts table
public function showSinglePost(Category $category, $slug)
{
$this->data['post'] = $category->belongsTo('App\Post', $slug, 'slug')->get();
dd($this->data['post']);
}
Answer the question
In order to leave comments, you need to log in
Write belongsTo in the model itself, and load via $category->load('post') if your category is already selected. Or $category->with('posts')->get() if the category is not loaded, because the relay needs to get data from the category itself in order to pull related posts.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question