Answer the question
In order to leave comments, you need to log in
How do I get "Offline App" status for my extension in the Chrome Extension Store?
How do I get "Offline App" status for my extension in the Chrome Extension Store?
Answer the question
In order to leave comments, you need to log in
Hey! Let's go in order :)
1. Since you have a many-to-many relationship (if this is not the case, it will be different), then you correctly made the third plate. You don't need to make a model for it! The relationship will look like this:
Category Model: Category.php
protected $table = 'categories';
public function posts()
{
return $this->belongsToMany('App\Models\Post', 'post_id', 'category_id);
}
protected $table = 'posts';
public function categories()
{
return $this->belongsToMany('App\Models\Category', 'post_id', 'category_id);
}
$post = Post::where('slug', $slug)->first(); -----> равенство идет по дефолту
$categories = $post->categories;
foreach ($categories as $category)
{
echo $category->id. '<br>'; -----------------> любые данные категории.
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question