文章分类由1变多
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Traits\HasOneCover;
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Category extends Model
|
||||
@@ -44,7 +45,7 @@ class Category extends Model
|
||||
return $this->hasOne(Article::class, 'id', 'article_id');
|
||||
break;
|
||||
case self::TYPE_ARTICLE:
|
||||
return $this->hasMany(Article::class);
|
||||
return $this->belongsToMany(Article::class);
|
||||
break;
|
||||
case self::TYPE_ADVERT:
|
||||
return $this->hasMany(Advert::class);
|
||||
@@ -64,4 +65,9 @@ class Category extends Model
|
||||
return $this->hasMany(__CLASS__, 'parent_id');
|
||||
}
|
||||
|
||||
public function articles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Article::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user