Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

a0e's avatar
Level 4

Custom request auth

In the User model I have a value isTeacher and in a custom request called ServiceProvider I am checking if the isTeacher in the user is set to 1. When accessing the user through auth()->user()->isTeacher an error is thrown saying its accessing null values so is there any special way to check for auth in custom requests?

0 likes
3 replies
tykus's avatar

It would appear that there is no auth()->user() for some reason. What is a custom request; can you show the Route definition, attached middlewares?

a0e's avatar
Level 4

i forgot to add the auth middleware to the route, but thanks

a0e's avatar
Level 4

nvrmind I just found the solution, in the API i didnt specify for it to go through the auth:api middleware, so thats why i couldnt access the auth in the request

Please or to participate in this conversation.