Мне нужна помощь, пожалуйста.
У меня есть две модели, Country
и Buy
, с Many to many relationship
между ними. Я использую пакет Laravel Datatables от Yajra для отображения таблица всех стран и покупок.
Страны
Schema::create('countries', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
Покупки
Schema::create('buys', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('code_one');
$table->integer('code_two');
$table->timestamps();
});
страна_покупки
Schema::create('buy_country', function (Blueprint $table) {
$table->increments('id');
$table->integer('buy_id');
$table->integer('country_id');
$table->timestamps();
});
Модели
class Country extends Model
{
public function buys(){
return $this->belongsToMany('App\Buy', 'buy_country');
}
}
class Buy extends Model
{
public function countries(){
return $this->belongsToMany('App\Country', 'buy_country');
}
}
Я хочу отображать название страны в первой строке и продукты из таблицы покупок в дочерних строках.
Как я могу это сделать, с пакетом Yajra или без него?