阶段性更新
This commit is contained in:
@@ -3,19 +3,26 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use App\Models\Traits\HasCovers;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
|
||||
use HasOneCover, BelongsToCategory;
|
||||
use HasCovers, BelongsToCategory;
|
||||
|
||||
public function getLinkAttribute()
|
||||
public function getLinkAttribute(): string
|
||||
{
|
||||
return route('article.show', $this);
|
||||
}
|
||||
|
||||
/***
|
||||
* Notes: 获取详情内图片
|
||||
* @Author: 玄尘
|
||||
* @Date : 2021/10/8 11:58
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function get_content_cover()
|
||||
{
|
||||
preg_match("/<img.*?src=\"([^\"]+)\"[^>].*?>/isU", str_ireplace("\\", "", $this->content), $matches);
|
||||
@@ -35,12 +42,11 @@ class Article extends Model
|
||||
*/
|
||||
public function get_one_cover()
|
||||
{
|
||||
if ($this->cover_path) {
|
||||
$path = $this->cover_path;
|
||||
if ($this->cover_url) {
|
||||
$path = $this->cover_url;
|
||||
} else {
|
||||
$path = $this->get_content_cover();
|
||||
if ($path) {
|
||||
|
||||
$this->cover = str_replace("/storage", "", $path);
|
||||
$this->save();
|
||||
$path = config('app.url') . $path;
|
||||
@@ -65,6 +71,11 @@ class Article extends Model
|
||||
->using(ArticleCategory::class);
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: description
|
||||
* @Author: 玄尘
|
||||
@@ -79,9 +90,11 @@ class Article extends Model
|
||||
$ids = [$ids];
|
||||
}
|
||||
|
||||
return $query->whereHas('categories', function ($q) use ($ids) {
|
||||
$q->whereIN('id', $ids);
|
||||
});
|
||||
return $query->whereIn('category_id', $ids);
|
||||
//
|
||||
// return $query->whereHas('categories', function ($q) use ($ids) {
|
||||
// $q->whereIN('id', $ids);
|
||||
// });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user