سؤال

I want to make more than one where on a query with Eloquent. Basically you have this :

<?php

    User::where('gender', '=', 'male')->where('age', '=', '18')->get();

?>

So imagine you have a foreach which turns twice to concatenate that two where clause. How could you do ?

$user = User::where('gender', '=', 'male')
foreach ($array as $key => $value) {
    $user .= $user->where($key, '=', $value);
}

Do you see what I mean ? I know that my example is not possible at all.. but it's to explain.

Thank you !

هل كانت مفيدة؟

المحلول

You can do the following.

$user = User::where('gender', 'male');

// Now add on a chain with loops or whatever expression you need.
$user = $user->where('field', 'value');

// Now get the results
$user = $user->get();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top