feature
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user