I cant retrieve authenticated webmaster in controller. As you can see below, i authenticate user in constructor via $this->middleware
:
class DomainController
.....
public function __construct()
{
$this->middleware('auth:webmasters');
}
public function requestNewName(Request $request, Webmaster $webmaster, DomainRepositoryInterface $domainRepository): array
{
// $webmaster->id === null here
/** @var Webmaster $webmaster */
$webmaster = Auth::user(); // $webmaster->id === 1, all OK
$domainRepository->requestChangeName($webmaster, $request->input('newName', ''));
return ['result' => true];
}
....
I think i need to bind it somewhere, but i dont understand where or how?
P. S.
Now i have in AuthServiceProvider:
foreach ([Webmaster::class, Admin::class] as $class) {
$this->app->bind($class, static function($app) use ($class) {
$authenticated = Auth::user();
/** @noinspection GetClassUsageInspection */
return $authenticated && get_class($authenticated) === $class ? $authenticated : null;
});
}
}
And call this function in boot method. I bet that laravel has something for it.