How to conditions in multiple associated table in laravel 5.2
<p>i am facing one problem. Can anyone help me
Firstly I have two Models</p>

<p>1)User.php</p>

<pre><code>enter code here
public function listings(){
    return $this-&gt;hasOne('App\Listing','user_id')
          -&gt;with("topservices");
}
</code></pre>

<p>Now i have Listing Model</p>

<p>2) (Listing.php)</p>

<pre><code>enter code here
public function topservices(){
    return $this-&gt;hasMany('App\Sellerprofile','list_id');
}
</code></pre>

<p>Now i have one function</p>

<pre><code>enter code here
public function nails(){
    $users = DB::table('users')
        -&gt;where(['service_name'=&gt;"Seller"])
        -&gt;get();
    $users = json_decode(json_encode($users),true);
    foreach($users as $alluser){
        $ids[] = $alluser['id']; 
    }
    if(!empty($ids)){
            $allData = User::with('listings')-&gt;whereIn('id',$ids)-&gt;get();
            $allData = json_decode(json_encode($allData),true);
            echo "&lt;pre&gt;"; print_r($allData); die; ///when i print this array it gives me below output

    } 
    $title = "Nails";
    return view("listings.listing",['allData'=&gt;$allData,'title'=&gt;$title]);
}
</code></pre>

<p>Output:</p>

<pre><code>enter code here
Array
(
[0] =&gt; Array
    (
        [id] =&gt; 1
        [title] =&gt; Mr
        [firstname] =&gt; kunal
        [email] =&gt; kunal@gmail.comsc
        [listings] =&gt; Array
            (
                [id] =&gt; 1
                [user_id] =&gt; 1
                [type] =&gt; premimum
                [business_name] =&gt; kunal
                [topservices] =&gt; Array
                    (
                        [0] =&gt; Array
                            (
                                [id] =&gt; 5
                                [service_id] =&gt; 1
                                [list_id] =&gt; 1
                                [name] =&gt; Acrylic 
                                [duration] =&gt; 10mins
                                [price] =&gt; 10
                            )

                        [1] =&gt; Array
                            (
                                [id] =&gt; 6
                                [service_id] =&gt; 2
                                [list_id] =&gt; 1
                                [name] =&gt; Hair Top
                                [duration] =&gt; 30mins
                                [price] =&gt; 20
                            )

                        [2] =&gt; Array
                            (
                                [id] =&gt; 7
                                [service_id] =&gt; 3
                                [list_id] =&gt; 1
                                [name] =&gt; Skin Care Top
                                [duration] =&gt; 1hr-30mins
                                [price] =&gt; 30
                            )

                        [3] =&gt; Array
                            (
                                [id] =&gt; 8
                                [service_id] =&gt; 4
                                [list_id] =&gt; 1
                                [name] =&gt; Massage Top
                                [duration] =&gt; 20mins
                                [price] =&gt; 50
                            )

                    )
            )

    )

[1] =&gt; Array
    (
        [id] =&gt; 2
        [title] =&gt; Mr
        [firstname] =&gt; kunal
        [email] =&gt; kunal@gmail.comsdsfd
        [listings] =&gt; Array
            (
                [id] =&gt; 2
                [user_id] =&gt; 2
                [type] =&gt; premimum
                [topservices] =&gt; Array
                    (
                        [0] =&gt; Array
                            (
                                [id] =&gt; 9
                                [service_id] =&gt; 6
                                [list_id] =&gt; 2
                                [name] =&gt; Acrylic 
                                [duration] =&gt; 30mins
                                [price] =&gt; 10
                            )

                        [1] =&gt; Array
                            (
                                [id] =&gt; 10
                                [service_id] =&gt; 6
                                [list_id] =&gt; 2
                                [name] =&gt; Powder gel nails 
                                [duration] =&gt; 45mins
                                [price] =&gt; 20
                            )

                        [2] =&gt; Array
                            (
                                [id] =&gt; 11
                                [service_id] =&gt; 6
                                [list_id] =&gt; 2
                                [name] =&gt; Polish change
                                [duration] =&gt; 10mins
                                [price] =&gt; 25
                            )

                        [3] =&gt; Array
                            (
                                [id] =&gt; 12
                                [service_id] =&gt; 6
                                [list_id] =&gt; 2
                                [name] =&gt; Hand design
                                [duration] =&gt; 2hrs
                                [price] =&gt; 100
                            )

                        [4] =&gt; Array
                            (
                                [id] =&gt; 13
                                [service_id] =&gt; 7
                                [list_id] =&gt; 2
                                [name] =&gt; Hair Top
                                [duration] =&gt; 30mins
                                [price] =&gt; 200
                            )

                    )
            )

    )
)
</code></pre>

<p>Now you seen above output there is Topservices array i want all those array under topservices whose price is greater than= 10 and less than equal to 30 
My expected Output is:-</p>

<pre><code>enter code here
Array
(
[0] =&gt; Array
    (
        [id] =&gt; 1
        [title] =&gt; Mr
        [firstname] =&gt; kunal
        [email] =&gt; kunal@gmail.comsc
        [listings] =&gt; Array
            (
                [id] =&gt; 1
                [user_id] =&gt; 1
                [type] =&gt; premimum
                [business_name] =&gt; kunal
                [topservices] =&gt; Array
                    (
                        [0] =&gt; Array
                            (
                                [id] =&gt; 5
                                [service_id] =&gt; 1
                                [list_id] =&gt; 1
                                [name] =&gt; Acrylic 
                                [duration] =&gt; 10mins
                                [price] =&gt; 10
                            )

                        [1] =&gt; Array
                            (
                                [id] =&gt; 6
                                [service_id] =&gt; 2
                                [list_id] =&gt; 1
                                [name] =&gt; Hair Top
                                [duration] =&gt; 30mins
                                [price] =&gt; 20
                            )
                    )
            )

    )

[1] =&gt; Array
    (
        [id] =&gt; 2
        [title] =&gt; Mr
        [firstname] =&gt; kunal
        [email] =&gt; kunal@gmail.comsdsfd
        [listings] =&gt; Array
            (
                [id] =&gt; 2
                [user_id] =&gt; 2
                [type] =&gt; premimum
                [topservices] =&gt; Array
                    (
                        [0] =&gt; Array
                            (
                                [id] =&gt; 9
                                [service_id] =&gt; 6
                                [list_id] =&gt; 2
                                [name] =&gt; Acrylic 
                                [duration] =&gt; 30mins
                                [price] =&gt; 10
                            )

                        [1] =&gt; Array
                            (
                                [id] =&gt; 10
                                [service_id] =&gt; 6
                                [list_id] =&gt; 2
                                [name] =&gt; Powder gel nails 
                                [duration] =&gt; 45mins
                                [price] =&gt; 20
                            )

                        [2] =&gt; Array
                            (
                                [id] =&gt; 11
                                [service_id] =&gt; 6
                                [list_id] =&gt; 2
                                [name] =&gt; Polish change
                                [duration] =&gt; 10mins
                                [price] =&gt; 25
                            )

                    )
            )

    )
)
</code></pre>

<p>Can anyone help me. Thanks in advance What i do in nails function</p>