Mugluck Mugluck - 1 year ago 72
MySQL Question

What's a simple way to match two sets of data? Laravel 5.3

I have a users table and I have an agencies table. Users at the moment do not belong to agencies, nor do agencies belong to users. Our job is to match them on certain criteria.

Let's say users have a time commitment and language preference. The database is relational, so I can call the commitments of agencies and users respectively when needed.

I'd like to be able to automatically show a user, or agency, the accounts that are matched with them and be able to call that data when needed. For instance when the user logs in, the backend checks the agencies for time commitment and preferences and holds the ids and relevant matching points for display on various pages (most likely through little info cards).

Now I have things set up with a profile composer that can load important data in the background and serve that to users when needed but I'm stumped on the matching. I can't figure out where best to load the information, how to reduce potential database overheads, or ultimately because I'm new how I should do a comparison and return potential matches.

Can someone point me in the right direction?

Edit Note: Most matching data is in pivot relationships, which I'm also not sure how to call to get a match.

Answer Source

If the commitment and language preference are fields on both the user and the agency tables, you could use basic eloquent query e.g.

$agents = Agent::where('language', 'like', Auth::user()->language)->get();

That will return the list of agents that share a particular language with the user.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download