I have a controller with a store()
method called from a Vue component. It works fine, as I can successfully pass data to my controller from the Vue component. But, I am trying to get the identity of the authenticated user, and for some reason, I can not do that inside of the controller method. What I am currently doing is checking if there is an authenticated user (which there should be, auth is set up, and when I check on the front end in a blade template auth()->check()
returns true).
Controller
public function store(Request $request)
{
$player = Player::create([
'first_name' => $request['first_name'],
'last_name' => $request['last_name'],
'dob' => $request['dob'],
]);
If (auth()->check()) {
Mail::to(auth()->user())->send(new PlayerCreated($player));
}
}
I am also importing Illuminate\Support\Facades\Auth,
so it is not an issue of not having use of the Auth
facade. But, for some reason, it is not working.
I am wondering if it has something to do with this being an API route? I can't seem to figure out why I still wouldn't be able to access the authenticated user in my controller. Any ideas on why this is happening and how to fix?