我有这些桌子的 struct
1. main_categories
id -> integer = 1
name -> string
updated_at -> Null
created_at -> 2022/08/22
2. sub_categories
***Row 1***
id -> integer = 10
name -> string
category_id-> 1
translation_lang -> en
translation_of -> 0
name -> string = Game
category_id-> 1
updated_at -> Null
created_at -> 2022/08/22
2. sub_categories // Row 2
***Row 2*** // Row 2
id -> integer
name -> string
category_id-> 1
translation_lang -> ar
translation_of -> 10
name -> string = لعبة
category_id-> 1
updated_at -> Null
created_at -> 2022/08/22
默认语言为En
;
翻译_语言是name -> string
translation.
TRANSPECTION_OF是转换为行1 id.它具有默认语言
我想从main_categories
号桌拿到sub_categories
Row 2
These Are My Models:
100
class main_category extends Model
{
protected $table = 'main_categories';
protected $fillable = [
'name' ,'id' ,'created_at' , 'updated_at'
];
public function subCategoriesTranslation() {
// Here i Want to make relationship to get ***Row 2*** from subcategories Table How can i make it?
}
}
100
class SubCategory extends Model
{
use HasFactory;
protected $table = 'sub_categories';
protected $fillable = [
'translation_lang','translation_of' ,'category_id' , 'name' ,'created_at' , 'updated_at',
];
}
问题总结:我想从maincategory table得到subcategories table中的row 2