2025-07-23 15:41:01 +09:00
|
|
|
<?php
|
|
|
|
|
|
2025-07-29 13:00:25 +09:00
|
|
|
namespace App\Models\Commons;
|
2025-07-23 15:41:01 +09:00
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2025-08-16 03:25:06 +09:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2025-08-16 04:16:34 +09:00
|
|
|
use App\Traits\BelongsToTenant;
|
|
|
|
|
use App\Traits\ModelTrait;
|
|
|
|
|
use App\Models\Scopes\TenantScope;
|
2025-07-23 15:41:01 +09:00
|
|
|
|
2025-08-21 09:50:15 +09:00
|
|
|
/**
|
|
|
|
|
* @mixin IdeHelperMenu
|
|
|
|
|
*/
|
2025-07-23 15:41:01 +09:00
|
|
|
class Menu extends Model
|
|
|
|
|
{
|
2025-08-16 04:16:34 +09:00
|
|
|
use SoftDeletes, BelongsToTenant, ModelTrait;
|
2025-08-16 03:25:06 +09:00
|
|
|
|
2025-07-23 15:41:01 +09:00
|
|
|
protected $fillable = [
|
2025-08-16 04:16:34 +09:00
|
|
|
'tenant_id', 'parent_id', 'name', 'url', 'is_active', 'sort_order',
|
|
|
|
|
'hidden', 'is_external', 'external_url', 'icon',
|
|
|
|
|
'created_by', 'updated_by', 'deleted_by',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'created_by',
|
|
|
|
|
'updated_by',
|
|
|
|
|
'deleted_by',
|
|
|
|
|
'deleted_at'
|
2025-07-23 15:41:01 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function parent()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Menu::class, 'parent_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function children()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Menu::class, 'parent_id');
|
|
|
|
|
}
|
2025-08-16 04:16:34 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 공유(NULL) + 현재 테넌트 모두 포함해서 조회
|
|
|
|
|
* (SoftDeletes 글로벌 스코프는 그대로 유지)
|
|
|
|
|
*/
|
|
|
|
|
public function scopeWithShared($query, ?int $tenantId = null)
|
|
|
|
|
{
|
|
|
|
|
$tenantId = $tenantId ?? app('tenant_id');
|
|
|
|
|
|
|
|
|
|
return $query
|
|
|
|
|
->withoutGlobalScope(TenantScope::class)
|
|
|
|
|
->where(function ($w) use ($tenantId) {
|
|
|
|
|
if (is_null($tenantId)) {
|
|
|
|
|
$w->whereNull('tenant_id');
|
|
|
|
|
} else {
|
|
|
|
|
$w->whereNull('tenant_id')->orWhere('tenant_id', $tenantId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-07-23 15:41:01 +09:00
|
|
|
}
|