query

3 years ago

RomanAntDev

Code

$consultants = User::whereRole('consultant');

if ($request->has('exp_from')) {
  $consultants->has('experiences')->withSum('experiences', 'exp_month');
  $sumExp = $consultants->get('experiences_sum_exp_month');
  $sumExp->each(function ($exp) use ($request) {
    if ($exp->experiences_sum_exp_month >= $request['exp_from']) {
      $res[] = $exp;
    }
  });
}

$consultants->paginate();

Output

[!] Aliasing 'User' to 'App\Models\User' for this Tinker session.
PHP Notice:  Undefined variable: request in phar:///tmp/.mount_TinkerdA0qkS/resources/tinkerwell/tinker.phar/index.php(206) : eval()'d code on line 2
CustomErrorException with message 'PHP Error:  Call to a member function has() on null in phar:///tmp/.mount_TinkerdA0qkS/resources/tinkerwell/tinker.phar/index.php(206) : eval()'d code on line 2'
New course: Desktop apps with Electron