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

Shalini's avatar

Laravel find method

I am trying to find the users based on their roles and trying to send notifications to the respective role. But if I use the find method it works only works for "id" since id is a primarykey. $User = user::find(1); User::find(1)->notify(new role1);

If I use the following code I am getting an error "syntax error, unexpected 'User' (T_STRING)" $User = user::where('roleNo', 1); User::where('roleNo', 1)->notify(new role1);

Can anyone please suggest to me a solution to this problem? Is there any other way to find the nonprimary integer value?

0 likes
3 replies
MichalOravec's avatar
User::where('roleNo', 1)->firstOrFail()->notify(new Role1);
Shalini's avatar

Thank you so much. It is working.

Please or to participate in this conversation.