Support the ongoing development of Laravel.io →
Database Mail Queues
Last updated 2 years ago.
0

After doing a little more digging, I found that the two facades are returning different information because a little piece of information that I accidentally left out was that I'm also using Spark.

It seems that Spark is injecting some functions to the User facade that I didn't realize.

Does anyone know if it is possible to put a Where clause on the User facade? So that I can return just the users that I need? This would help tremendously.

0

So, anyone trying to figure out this on their own, I have finally found the right solution and it was much simpler than I anticipated.

In your User model, just add this code:

public function scopeState($query, $state)
{
    return $query->where('emailNotification', 'like', '%'.$state.'%');
}

This essentially creates your own search query on the User facade. Now instead of calling User::all();, you just call User::state($state)->get(); and this returns exactly what I was looking for.

Hopefully, this will help someone else looking to do something similar.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.