I've been stuck onto a problem with laravel, since I'm new to this I try things, and things still don't work.
I have a search function that, seek through the users, using the name, the specialty of the user, or his location, the function work if you fill just one input, if you start to fill a second input, it show the first condition which is coded in the controller.
Exemple :
if i put
Name : -empty- Specialty : -empty- Location : New
It shows me everyone that lives in cities starting with "New", but if I do
Name : Maria Specialty : -empty- Location : New
It shows me everyone whose name is Maria, or, I want "Maria" who live in cities starting with "New"
So I search how to make my code work with that, making if inside of if, making double condition, but since I'm with laravel I have trouble doing it (my version is 5.0, i'll go for update after this bug is resolved)
Here is the part where I'm stuck on, with things I tried,
if($attributs['specialty'] != "") {
$users = User::where('status_user', '=', '1')
->where('specialty_id', $attributs['specialty'])
->where('city', 'LIKE', '%'.$attributs['locality'].'%') //;
/* if($attributs['name']!= ""){
$query->where(function ($query) use ($name){
$query->where(('CONCAT(lastname, " ", firstname)'), 'LIKE', $name.'%')
->orWhere(('CONCAT(firstname, " ", lastname)'), 'LIKE', $name.'%');
})
}
->where('address', 'LIKE', '%'.$attributs['locality'].'%')
->where(DB::raw('CONCAT(address, " ", postal_code, " ", city)'), 'LIKE', '%'.$address.'%')*/
->confirmed()
->get();
}
else if($attributs['name'] != ""){
$users = User::where(function ($query) use ($name) {
$query->where(function ($query) use ($name) {
$query->where(DB::raw('CONCAT(lastname, " ", firstname)'), 'LIKE', $name.'%')
->orWhere(DB::raw('CONCAT(firstname, " ", lastname)'), 'LIKE', $name.'%');
})
->where('status_user', '=', '1')
->confirmed();
})
->orWhere(function ($query) use ($name) {
$query->where(function ($query) use ($name) {
$query->where(DB::raw('CONCAT(lastname, " ", firstname)'), 'LIKE', $name.'%')
->orWhere(DB::raw('CONCAT(firstname, " ", lastname)'), 'LIKE', $name.'%');
})
->where('status_user', '=', '1')
->where('invite', '=', '1');
})
->get();
}
else if($attributs['address'] != ""){
$users = User::where('status_user', '=', '1')
->where('address', 'LIKE', '%'.$attributs['locality'].'%')
->where(DB::raw('CONCAT(address, " ", postal_code, " ", city)'), 'LIKE', '%'.$address.'%')
->confirmed()
->get();
}
Thanks in advance, it's been days since I'm on it ><
Aucun commentaire:
Enregistrer un commentaire