调整页面

This commit is contained in:
2020-09-15 14:01:28 +08:00
parent 3ac390f68f
commit f91a3b76c1
20 changed files with 5068 additions and 642 deletions

View File

@@ -7,8 +7,14 @@ use App\Models\Traits\HasOneCover;
class Article extends Model
{
use HasOneCover, BelongsToCategory;
public function getLinkAttribute()
{
return route('article.show', $this);
}
public function get_content_cover()
{
preg_match("/<img.*?src=\"([^\"]+)\"[^>].*?>/isU", str_ireplace("\\", "", $this->content), $matches);
@@ -41,6 +47,7 @@ class Article extends Model
}
}
return $path;
}

View File

@@ -7,17 +7,22 @@ use Encore\Admin\Traits\ModelTree;
class Category extends Model
{
use AdminBuilder, ModelTree;
public const TYPES = [
'article' => '文章列表',
'show' => '文章详情',
'advert' => '广告',
];
public const TYPE_SHOW = 'show';
public const TYPE_SHOW = 'show';
public const TYPE_ARTICLE = 'article';
public const TYPE_ADVERT = 'advert';
public const TYPES = [
self::TYPE_ARTICLE => '文章列表',
self::TYPE_SHOW => '文章详情',
self::TYPE_ADVERT => '图片',
];
public function getLinkAttribute()
{
return route('category.show', $this);
}
/**
* 关联的数据
@@ -27,7 +32,7 @@ class Category extends Model
{
switch ($this->type) {
case self::TYPE_SHOW:
return $this->hasOne(Article::class)->where('id',$this->article_id);
return $this->hasOne(Article::class)->where('id', $this->article_id);
break;
case self::TYPE_ARTICLE:
return $this->hasMany(Article::class);
@@ -42,12 +47,12 @@ class Category extends Model
public function childrens()
{
return $this->hasMany(self::class,'parent_id');
return $this->hasMany(self::class, 'parent_id');
}
public function parent()
{
return $this->hasOne(self::class,'id','parent_id');
return $this->hasOne(self::class, 'id', 'parent_id');
}
public function article()