I'm trying to filter account in laravel.1 user can have many accounts with different format. It doesnt seem to work.The query:
$accounts = $user->account()->where('account_no','like', ['34%','35%','3303%','3304%'])->get();
i'm wondering if this can be done or not?
CodePudding user response:
You can't do that. For each condition you need a single WHERE condition, like this:
$accounts = $user->account()->where('account_no','like','34%')
->orWhere('account_no','like','35%')
->orWhere('account_no','like','3303%')
->orWhere('account_no','like','3304%')
->get();
That should do it.
CodePudding user response:
You can try this workaround :
$checks = array('34','35','3304','3305');
$accounts = $user->accounts()
->Where(function ($query) use($checks) {
foreach ($checks as $check){
$query->orwhere('account_no', 'like', $check .'%');
}
})->get();