Edit File: Category.php
<?php namespace App\Models; use App\Traits\ModelTrait; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Spatie\Translatable\HasTranslations; class Category extends BaseModel { use HasTranslations, ModelTrait; const IMAGEPATH = 'categories'; protected $fillable = ['name', 'parent_id', 'image']; public $translatable = ['name']; /** * Get all of the children for the Category * * @return HasMany */ public function children(): HasMany { return $this->hasMany(self::class, 'parent_id'); } /** * Get the parent that owns the Category * * @return BelongsTo */ public function parent(): BelongsTo { return $this->belongsTo(self::class, 'parent_id'); } public function getFollowedCategoryAttribute() { return $this->attributes['parent_id'] ? $this->parent->name : __('admin.main_section'); } public function scopeHead($query): mixed { return $query->whereNull('parent_id'); } }
Back to File Manager