64 lines
1.2 KiB
PHP
64 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
|
||
|
|
class Folder extends Model
|
||
|
|
{
|
||
|
|
use \App\Traits\BelongsToTenant;
|
||
|
|
use \App\Traits\ModelTrait;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'tenant_id',
|
||
|
|
'folder_key',
|
||
|
|
'folder_name',
|
||
|
|
'description',
|
||
|
|
'display_order',
|
||
|
|
'is_active',
|
||
|
|
'icon',
|
||
|
|
'color',
|
||
|
|
'created_by',
|
||
|
|
'updated_by',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'is_active' => 'boolean',
|
||
|
|
'display_order' => 'integer',
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the tenant that owns the folder
|
||
|
|
*/
|
||
|
|
public function tenant(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Tenant::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get all files in this folder
|
||
|
|
*/
|
||
|
|
public function files(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(File::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Scope: Active folders only
|
||
|
|
*/
|
||
|
|
public function scopeActive($query)
|
||
|
|
{
|
||
|
|
return $query->where('is_active', true);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Scope: Ordered by display_order
|
||
|
|
*/
|
||
|
|
public function scopeOrdered($query)
|
||
|
|
{
|
||
|
|
return $query->orderBy('display_order');
|
||
|
|
}
|
||
|
|
}
|