43 lines
933 B
PHP
43 lines
933 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace plugin\produce\app\model;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Material extends BaseModel
|
|
{
|
|
protected $table = 'produce_material';
|
|
|
|
protected $appends = ['created_date', 'updated_date', 'category_name'];
|
|
|
|
protected $fillable = [
|
|
'id',
|
|
'category_id',
|
|
'product_code',
|
|
'product_name',
|
|
'created_by',
|
|
'updated_by',
|
|
'created_at',
|
|
'updated_at',
|
|
'deleted_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'created_at' => 'integer',
|
|
'updated_at' => 'integer',
|
|
'deleted_at' => 'integer',
|
|
];
|
|
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(MaterialCategory::class, 'category_id', 'id')->withTrashed();
|
|
}
|
|
|
|
public function getCategoryNameAttribute(): string
|
|
{
|
|
return (string) ($this->category?->category_name ?? '');
|
|
}
|
|
}
|