feat: add sub category for media
This commit is contained in:
@@ -12,5 +12,10 @@ public function questions()
|
||||
{
|
||||
return $this->hasMany(Question::class);
|
||||
}
|
||||
|
||||
public function subcategories()
|
||||
{
|
||||
return $this->hasMany(SubCategory::class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class Media extends Model
|
||||
'user_id',
|
||||
'image_id',
|
||||
'category_id',
|
||||
'subcategory_id',
|
||||
'title',
|
||||
'caption',
|
||||
'type',
|
||||
@@ -48,6 +49,11 @@ public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function subCategory()
|
||||
{
|
||||
return $this->belongsTo(SubCategory::class, 'subcategory_id');
|
||||
}
|
||||
public function tags()
|
||||
{
|
||||
return $this->belongsToMany(Tag::class, 'media_tag');
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class SubCategory extends Model
|
||||
{
|
||||
protected $table = 'sub_categories';
|
||||
|
||||
protected $fillable = ['category_id', 'name'];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function media(): HasMany
|
||||
{
|
||||
return $this->hasMany(Media::class, 'subcategory_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user