I do have simple query working properly but I want it working properly using ORM.
Right now I have this query, which is working fine.
DB::select("select career_solutions.*, users.username, users.profile_picture from career_solutions inner join users on users.id = career_solutions.user_id inner join privacy_settings on privacy_settings.user_id = users.id where career_solutions.topic_category_id = $categoryId and ((privacy_settings.career_solutions = 0 and public = 1 ) or ((users.id in (select contacts.contact_id from contacts where contacts.user_id = $id) or users.id = $id))) order by date desc limit 5000");
I am trying to do same using ORM/laravel elaquent. Using this I am not getting same result as above. Some thing is wrong with the below query.
$career_solution = CareerSolution::with('user.role','user.privancy_setting','category','sub_category','country');
$career_solution = $career_solution->where(function ($query) {
$query->where('expires_at','>=', date('Y-m-d'))
->orWhere('expires_at', '=', '0000-00-00');
});
$career_solution = $career_solution->Where(function ($query1) use($id) {
$query1->Where(function ($query2) use($id) {
$query2->whereHas('user.privancy_setting', function ($query3) {
$query3->where('privacy_settings.career_solutions', '=', 0);
})->where('public','=',1);
})->orWhere(function ($query4) use($id) {
$query4->whereHas('user.contact', function ($query5) use ($id) {
$query5->where('contacts.user_id', '=', $id);
})->orWhere('user_id','=',$id);
});
});
}
It is not showing same result as above, let me know how I make it same as above.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2xzx2yT
via IFTTT
Aucun commentaire:
Enregistrer un commentaire