35 lines
752 B
PHP
35 lines
752 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class Categories extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = "Categories";
|
|
protected $primaryKey = "id";
|
|
public $incrementing = true;
|
|
public $timestamps = true;
|
|
protected $casts = [
|
|
'created_at' => 'timestamp',
|
|
'updated_at' => 'timestamp',
|
|
];
|
|
|
|
public function Produits(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany('App\Models\Produits', 'produits_categories', 'categories_id', 'products_id');
|
|
}
|
|
|
|
public function setDataTree() {
|
|
foreach ($this->Produits as $p) {
|
|
$p->setCalculatedFields();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|