调整分类
This commit is contained in:
@@ -4,18 +4,21 @@ namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
|
||||
use HasOneCover, BelongsToCategory;
|
||||
use HasOneCover;
|
||||
|
||||
public function getLinkAttribute()
|
||||
public function getLinkAttribute(): string
|
||||
{
|
||||
return route('article.show', $this);
|
||||
}
|
||||
|
||||
public function get_content_cover()
|
||||
|
||||
public function get_content_cover(): string
|
||||
{
|
||||
preg_match("/<img.*?src=\"([^\"]+)\"[^>].*?>/isU", str_ireplace("\\", "", $this->content), $matches);
|
||||
|
||||
@@ -26,6 +29,22 @@ class Article extends Model
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 关联分类的中间表
|
||||
* @Author: 玄尘
|
||||
* @Date : 2021/4/1 15:19
|
||||
*/
|
||||
public function article_categories(): HasMany
|
||||
{
|
||||
return $this->hasMany(ArticleCategory::class);
|
||||
}
|
||||
|
||||
public function categories(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Category::class)
|
||||
->using(ArticleCategory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取一个默认图片
|
||||
* @Author: 玄尘
|
||||
|
||||
Reference in New Issue
Block a user