38 lines
707 B
PHP
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;
|
|
}
|
|
}
|