44 lines
843 B
PHP
44 lines
843 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class StoreCategory extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'store_category';
|
|
|
|
protected $fillable = ['name', 'image'];
|
|
|
|
public function categories()
|
|
{
|
|
return $this->hasMany(StoreCategoryMap::class);
|
|
}
|
|
|
|
public function locations()
|
|
{
|
|
return $this->hasMany(StoreCapacity::class);
|
|
}
|
|
|
|
public function items()
|
|
{
|
|
return $this->hasMany(Items::class, 'category_id', 'id');
|
|
}
|
|
|
|
public function productCount()
|
|
{
|
|
return $this->items()->count();
|
|
}
|
|
|
|
|
|
public function getImageUrlAttribute()
|
|
{
|
|
return $this->image ? Storage::disk('wms')->url($this->image) : null;
|
|
}
|
|
|
|
}
|