It depends on the cardinality and the foreign_keys that are involved.
Products
-- Categories
--- SubCategories
---- Marks
----- Suppliers
The context that you gave me, I'm guessing that each table depends on the previous one as showed in the context that you gave. If so, then you can do the following:
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class Suppliers extends Model
{
protected $fillable = [.... ];
public function mark()
{
return $this->belongsTo(Mark::class);
}
}
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class Marks extends Model
{
protected $fillable = [.... ];
public function subCategorie()
{
return $this->belongsTo(SubCategorie::class);
}
}
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class SubCategory extends Model
{
protected $fillable = [.... ];
public function categorie()
{
return $this->belongsTo(Categorie::class);
}
}
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class Categorie extends Model
{
protected $fillable = [.... ];
public function categorie()
{
return $this->belongsTo(Product::class);
}
}
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class Product extends Model
{
protected $fillable = [.... ];
}
For more in depht inormation, you can consult the section about relationshipts on laravel docs: https://laravel.com/docs/8.x/eloquent-relationships.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…