laravel where in array
$items = Item::whereIn('id', [1,2,..])->get();
laravel where in array
$items = Item::whereIn('id', [1,2,..])->get();
laravel where in array
$items = DB::table('items')->whereIn('id',[1,2,..])->get();
search query in laravel
$searchTerm ='milad zamir Abc';
$reservedSymbols = ['-', '+', '<', '>', '@', '(', ')', '~'];
$searchTerm = str_replace($reservedSymbols, ' ', $searchTerm);
$searchValues = preg_split('/\s+/', $searchTerm, -1, PREG_SPLIT_NO_EMPTY);
$res = User::where(function ($q) use ($searchValues) {
foreach ($searchValues as $value) {
$q->orWhere('name', 'like', "%{$value}%");
$q->orWhere('family_name', 'like', "%{$value}%");
}
})->get();
laravel where in array
$items = Item::whereIn('id', [1,2,..])->get();
laravel search inside array column
Solution1: ->whereJsonContains('user_id', 3)
Solution2: ->whereRaw("JSON_CONTAINS(user_id, '[3]' )")
Solution3: ->where('user_id','like',"%{$id}%")
Solution4: Person::hasJob($job->id);
// Inside Model
public function scopeHasJob($query, $jobId)
{
return $query->where('user_id', 'like', "%\"{$userId}\"%");
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us