二次改版
This commit is contained in:
@@ -2,21 +2,23 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use App\Models\Traits\HasCovers;
|
||||
use App\Models\Traits\HasSort;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
|
||||
use HasOneCover;
|
||||
use HasCovers,HasSort;
|
||||
|
||||
/**
|
||||
* 应进行类型转换的属性
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'subjoin' => 'array',
|
||||
'subjoin' => 'array',
|
||||
'pictures' => 'array',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
@@ -26,6 +28,7 @@ class Article extends Model
|
||||
|
||||
/**
|
||||
* Notes: 关联分类
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2021/4/2 9:11
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
@@ -33,11 +36,12 @@ class Article extends Model
|
||||
public function categories(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Category::class)
|
||||
->using(ArticleCategory::class);
|
||||
->using(ArticleCategory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: description
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2021/4/2 9:17
|
||||
* @param $query
|
||||
@@ -46,7 +50,7 @@ class Article extends Model
|
||||
*/
|
||||
public function scopeByCategory($query, $ids)
|
||||
{
|
||||
if (!is_array($ids)) {
|
||||
if (! is_array($ids)) {
|
||||
$ids = [$ids];
|
||||
}
|
||||
|
||||
@@ -55,4 +59,16 @@ class Article extends Model
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getDateD()
|
||||
{
|
||||
return $this->created_at->format('d');
|
||||
}
|
||||
|
||||
public function getDateYM()
|
||||
{
|
||||
return $this->created_at->format('Y-m');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user