I am creating a recommendation system using Laravel php and sql. The user enters values during registration and they are stored in the user table.
Here is my users table schema , any field that has the recommendation name format e.g recommendationLocation is the location of the user the system should search for.
TABLE `users` (
`id` (int),
`username` (varchar),
`email` (varchar),
`password` (varchar),
`age` (varchar),
`location` (varchar),
`country` (varchar),
`userType` (varchar),
`religion` (varchar),
`variable1` (varchar),
`variable2` (varchar),
`recommendationAge` (varchar),
`recommendationLocation` (varchar),
`recommendationReligion` (varchar),
`recommendationVariable1` (varchar),
`recommendationVariable2` (varchar),
`recommendationUserType` (varchar),
`recommendationHairColor` (varchar),
`recommendationCountry` (varchar),
)
The below statement would be a perfect straight forward user match but not all users will enter the identical information. My problem is that there are a lot of different variables that I have to consider as there are a high amount of combinations. As I want to be able to still find a user even if the user doesn't have certain matching info. For example, The statement could only have one matching field but the query still returns the username with this matching field.
$recommendationQuery = DB::table('users')
->select('username')
->where('id', '!=', Auth::id()) // Can't be the current Auth User Details
->where('age', '=' , Auth::user()->recommendationAge) // This is a required where clause for all statements
->where('location', '=', Auth::user()->recommendationLocation) // This is a required where clause for all statements
->where('religion', '=', Auth::user()->recommendationReligion)
->where('variable1', '=', Auth::user()->recommendationVariable1)
->where('variable2', '=', Auth::user()->recommendationVariable2)
->where('age', '=', Auth::user()->recommendationAge)
->where('location', '=', Auth::user()->recommendationLocation)
->where('country', '=', Auth::user()->recommendationCountry)
->where('hairColor', '=', Auth::user()->recommendationHairColor)
->get();
Are there any alternative and more efficient ways? thanks