47 lines
1016 B
PHP
47 lines
1016 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\BelongsToCompany;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class MediaDirectory extends Model
|
|
{
|
|
use BelongsToCompany;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'slug',
|
|
'parent_id',
|
|
'created_by',
|
|
'creator_id',
|
|
];
|
|
|
|
public function media(): HasMany
|
|
{
|
|
return $this->hasMany(\Spatie\MediaLibrary\MediaCollections\Models\Media::class, 'directory_id');
|
|
}
|
|
|
|
public function parent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(self::class, 'parent_id');
|
|
}
|
|
|
|
public function children(): HasMany
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id');
|
|
}
|
|
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'creator_id');
|
|
}
|
|
|
|
public function createdBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
}
|