Files
coruna-lab/app/Http/Controllers/Concerns/PortalAware.php
T
hashbro 74a67c3900 init
2026-08-08 05:09:01 +08:00

38 lines
707 B
PHP

<?php
namespace App\Http\Controllers\Concerns;
use App\Models\User;
trait PortalAware
{
protected function portal(): string
{
$name = request()->route()?->getName() ?? '';
return str_starts_with($name, 'user.') ? 'user' : 'admin';
}
protected function isAgentPortal(): bool
{
return $this->portal() === 'user';
}
protected function agent(): ?User
{
if (! $this->isAgentPortal()) {
return null;
}
/** @var User|null $user */
$user = auth('agent')->user();
return $user;
}
protected function routeName(string $suffix): string
{
return $this->portal().'.'.$suffix;
}
}