سلام و خسته نباشید.یک جدول ساختم به نام دسته بندی (category) و دو تا جدول دیگه هم دارم به نام های یادداشت (notes) و کلمات(words) .هر کدوم از این جداول با جدول میانی خودشون (pivot table) به جدول دسته بندی مرتبط شدن، حالا سوالم اینه چطور تمامی دسته های مورد نظر notes یا words رو کوئری کنیم ؟به روش eloquent میخام ؟
MIGRATION:
Schema::create('categories', function (Blueprint $table) { ....
Schema::create('words', function (Blueprint $table) { ....
Schema::create('english_category', function (Blueprint $table){
$table->bigInteger('category_id');
$table->bigInteger('english_id');
$table->primary(['english_id','category_id']);
});
Schema::create('note_category', function (Blueprint $table){
$table->bigInteger('category_id');
$table->bigInteger('note_id');
$table->primary(['note_id','category_id']);
});
MODEL:
model category :
public function words()
{
return $this->belongsToMany(words::class,'english_category');
}
public function notes(){
return $this->belongsToMany(Note::class,'note_category');
}
model notes and words :
public function categories(){
return $this->belongsToMany(Category::class,'note_category');
}
public function user(){
return $this->belongsTo(User::class);
}شاید پاسخ شما همینجا باشد