feat: add sub category for media

This commit is contained in:
2026-05-30 20:39:53 +03:30
parent 230bfc2ad8
commit 56f0e8dbe2
9 changed files with 288 additions and 24 deletions
+5
View File
@@ -12,5 +12,10 @@ public function questions()
{
return $this->hasMany(Question::class);
}
public function subcategories()
{
return $this->hasMany(SubCategory::class);
}
}
+6
View File
@@ -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');
+24
View File
@@ -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');
}
}