feat: Many category and Many sub-category media
This commit is contained in:
@@ -17,5 +17,10 @@ public function subcategories()
|
||||
{
|
||||
return $this->hasMany(SubCategory::class);
|
||||
}
|
||||
|
||||
public function media()
|
||||
{
|
||||
return $this->belongsToMany(Media::class, 'category_media');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,6 @@ class Media extends Model
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'image_id',
|
||||
'category_id',
|
||||
'subcategory_id',
|
||||
'title',
|
||||
'caption',
|
||||
'type',
|
||||
@@ -45,14 +43,14 @@ public function image()
|
||||
return $this->belongsTo(Image::class);
|
||||
}
|
||||
|
||||
public function category()
|
||||
public function categories()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
return $this->belongsToMany(Category::class, 'category_media');
|
||||
}
|
||||
|
||||
public function subCategory()
|
||||
public function subCategories()
|
||||
{
|
||||
return $this->belongsTo(SubCategory::class, 'subcategory_id');
|
||||
return $this->belongsToMany(SubCategory::class, 'media_sub_category');
|
||||
}
|
||||
public function tags()
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class SubCategory extends Model
|
||||
{
|
||||
@@ -17,8 +17,8 @@ public function category(): BelongsTo
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function media(): HasMany
|
||||
public function media(): BelongsToMany
|
||||
{
|
||||
return $this->hasMany(Media::class, 'subcategory_id');
|
||||
return $this->belongsToMany(Media::class, 'media_sub_category');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user