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

kikter's avatar

syntax error

i want to get users that have roles for vendor, how can i do that

$vendor = Userd::latest()->where('role',== 'vendor')->get();
0 likes
5 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Are you using any packages ?

And to fix your query

$vendor = Userd::latest()->where('role', 'vendor')->get();

Sinnbeck's avatar

@kikter Ok so it works ? I dont know if your User model is actually called Userd. If not fix that as wlel

tykus's avatar

@kikter this is the invalid syntax;

where('role',== 'vendor')

Specifically the == is not a string. As @sinnbeck shows; it is in fact optional for equality checks:

where('role', '=', 'vendor')
// is equivalent to
where('role', 'vendor')

Note that this is only the case for equality checks - it you need to check <, >, <=, >= LIKE etc. then this operator will be a string second argument.

1 like

Please or to participate in this conversation.