Hello, if you are using eloquent, you don't need to fill the article_group table.
You just need to fill the relationships in your models, like that:
class Group extends Model
{
/**
* The articles that belong to the group.
*/
public function articles()
{
return $this->belongsToMany('App\Article');
}
}
class Article extends Model
{
/**
* The group that belong to the article.
*/
public function group()
{
return $this->belongsToMany('App\Group');
}
}
After that, the eloquent will do the job for you!
For example, to get the all the articles inside a group:
$articles = App\Group::find(1)->articles()->orderBy('name')->get();
Don't forget to import the models in your class too!
In the Article.php
use App\Group;
In the Group.php
use App\Article;
Here is the link to the docs:
https://laravel.com/docs/5.4/eloquent-relationships#many-to-many