初步完成
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -9,19 +10,24 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
|
||||
public const TYPES = [
|
||||
'article' => '文章列表',
|
||||
'show' => '文章详情',
|
||||
'advert' => '广告',
|
||||
'picture' => '图册',
|
||||
];
|
||||
use AdminBuilder, ModelTree, HasOneCover;
|
||||
|
||||
public const TYPE_SHOW = 'show';
|
||||
public const TYPE_ARTICLE = 'article';
|
||||
public const TYPE_ADVERT = 'advert';
|
||||
public const TYPE_PICTURE = 'picture';
|
||||
public const TYPE_PATENT = 'patent';
|
||||
public const TYPES = [
|
||||
self::TYPE_ARTICLE => '文章列表',
|
||||
self::TYPE_SHOW => '文章详情',
|
||||
self::TYPE_ADVERT => '图片',
|
||||
self::TYPE_PATENT => '专利',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('category.show', $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的数据
|
||||
@@ -31,7 +37,7 @@ class Category extends Model
|
||||
{
|
||||
switch ($this->type) {
|
||||
case self::TYPE_SHOW:
|
||||
return $this->hasOne(Article::class,'id','article_id');
|
||||
return $this->hasOne(Article::class, 'id', 'article_id');
|
||||
break;
|
||||
case self::TYPE_ARTICLE:
|
||||
return $this->hasMany(Article::class);
|
||||
|
||||
Reference in New Issue
Block a user