31 lines
644 B
PHP
31 lines
644 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Encore\Admin\Traits\AdminBuilder;
|
|
use Encore\Admin\Traits\ModelTree;
|
|
|
|
class Category extends Model
|
|
{
|
|
use AdminBuilder, ModelTree;
|
|
|
|
public function goods()
|
|
{
|
|
return $this->belongsToMany(Goods::class, 'goods_category')->withTimestamps();
|
|
}
|
|
|
|
public function getCoverPathAttribute()
|
|
{
|
|
if ($this->cover) {
|
|
return env('APP_URL') . '/storage/' . $this->cover;
|
|
} else {
|
|
return '/assets/index/img/product_active.png';
|
|
}
|
|
}
|
|
|
|
public function children()
|
|
{
|
|
return $this->hasMany(Category::class, 'parent_id', 'id');
|
|
}
|
|
}
|