xxxxxxxxxx
SELECT *
FROM `items`
WHERE EXISTS
(SELECT `items_city`.`id`
FROM `items_city`
WHERE items_city.item_id = items.id)
//Laravel
Item::query()
->whereExists(function ($query) {
$query->select("items_city.id")
->from('items_city')
->whereRaw('items_city.item_id = items.id');
})
->get();
xxxxxxxxxx
if (User::where('email', $request->email)->exists()) {
//email exists in user table
}
xxxxxxxxxx
//It depends if you want to work with the user afterwards or only check
//if one exists.
//If you want to use the user object if it exists:
$user = User::where('email', '=', Input::get('email'))->first();
if ($user === null) {
// user doesn't exist
}
//And if you only want to check
if (User::where('email', '=', Input::get('email'))->count() > 0) {
// user found
}
//Or even nicer
if (User::where('email', '=', Input::get('email'))->exists()) {
// user found
}
DB::table('items')
->whereExists(function ($query) {
$query->select("items_city.id")
->from('items_city')
->whereRaw('items_city.item_id = items.id');
})
->get();
xxxxxxxxxx
$repairJobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')
->where('active', '=', 'Y')
->whereNotExists(function($query)
{
$query->select(DB::raw(1))
->from('DismissedRequest')
->whereRaw('RepairJob.id = DismissedRequest.id');
})->get();