first commit
This commit is contained in:
68
Models/ProductCategory.php
Normal file
68
Models/ProductCategory.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user