69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Koneko\VuexyWarehouse\Models;
|
||
|
|
||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
use Illuminate\Database\Eloquent\Model;
|
||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
||
|
class ProductCategory extends Model
|
||
|
{
|
||
|
use HasFactory;
|
||
|
|
||
|
protected $table = 'product_categories';
|
||
|
protected $primaryKey = 'id';
|
||
|
public $incrementing = false;
|
||
|
protected $keyType = 'mediumint';
|
||
|
|
||
|
protected $fillable = [
|
||
|
'parent_id',
|
||
|
'parent_slug',
|
||
|
'name',
|
||
|
'slug',
|
||
|
'icon',
|
||
|
'description',
|
||
|
'show_in_pos',
|
||
|
'show_in_purchases',
|
||
|
'show_in_ecommerce',
|
||
|
'show_in_manufacturing',
|
||
|
'show_in_quality',
|
||
|
'show_in_assets',
|
||
|
'order'
|
||
|
];
|
||
|
|
||
|
protected $casts = [
|
||
|
'show_in_pos' => 'boolean',
|
||
|
'show_in_purchases' => 'boolean',
|
||
|
'show_in_ecommerce' => 'boolean',
|
||
|
'show_in_manufacturing' => 'boolean',
|
||
|
'show_in_quality' => 'boolean',
|
||
|
'show_in_assets' => 'boolean',
|
||
|
'order' => 'integer',
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* Relación con la categoría padre.
|
||
|
*/
|
||
|
public function parent(): BelongsTo
|
||
|
{
|
||
|
return $this->belongsTo(ProductCategory::class, 'parent_id');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Relación con categorías hijas.
|
||
|
*/
|
||
|
public function children(): HasMany
|
||
|
{
|
||
|
return $this->hasMany(ProductCategory::class, 'parent_id');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Relación con productos.
|
||
|
*/
|
||
|
public function products(): HasMany
|
||
|
{
|
||
|
return $this->hasMany(Product::class, 'category_id');
|
||
|
}
|
||
|
}
|