92 lines
1.8 KiB
PHP
92 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models\Market;
|
|
|
|
use App\Models\Model;
|
|
use App\Models\User;
|
|
|
|
class Product extends Model
|
|
{
|
|
|
|
protected ?string $table = 'prd_items';
|
|
protected string $primaryKey = 'id';
|
|
public bool $incrementing = true;
|
|
protected string $keyType = 'int';
|
|
|
|
protected array $fillable = [
|
|
'hashkey',
|
|
'created_by',
|
|
'updated_by',
|
|
'created_for',
|
|
'category',
|
|
'subcategory',
|
|
'logs',
|
|
'specs',
|
|
'photourl',
|
|
'available',
|
|
'sold',
|
|
'price',
|
|
// 'store_id',
|
|
'owner_id',
|
|
'views',
|
|
'name',
|
|
'description',
|
|
'reviews',
|
|
'barcode',
|
|
'status',
|
|
'remarks',
|
|
'unitname',
|
|
'rating',
|
|
'sku',
|
|
'qrcode',
|
|
'shortcode',
|
|
'shortname',
|
|
'is_active',
|
|
'product_type'
|
|
];
|
|
|
|
|
|
|
|
protected array $casts = [
|
|
'available' => 'integer',
|
|
'sold' => 'integer',
|
|
'price' => 'integer',
|
|
'views' => 'integer',
|
|
'rating' => 'integer',
|
|
'is_active' => 'boolean',
|
|
'photourl' => 'array',
|
|
'reviews' => 'array',
|
|
'specs' => 'array',
|
|
];
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function updater()
|
|
{
|
|
return $this->belongsTo(User::class, 'updated_by');
|
|
}
|
|
|
|
public function stores()
|
|
{
|
|
return $this->belongsToMany(Store::class, 'prd_str')
|
|
->withPivot(['available', 'price', 'is_active'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function owner()
|
|
{
|
|
return $this->belongsTo(User::class, 'owner_id');
|
|
}
|
|
|
|
public function createdFor()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_for');
|
|
}
|
|
|
|
}
|