Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 3 weeks ago.
0

Hello sir,

Use, before get(), take() and skip() methods. Like so:

http://laravel.io/bin/L4V

Last updated 3 weeks ago.
0

@hudsonpereira
Thanks for the reply, your example helped me get the records that I needed from the table. I tweaked your query to:

$posts = Post::with(
    array(
        'postChannels' => function($query){
            $q->where('is_main', '=', 1);
        }
    )
)
->where('status', '=', 1)
->take(2)
->get();    

I think my problem was not clear above so I edited it and wanted to know if this is the right approach? Thanks again!

Last updated 3 weeks ago.
0

Hm, try this:

$posts = Post::with(
    array(
        'postChannels' => function($query){
            $q->where('is_main', '=', 1);
        }
    )
)
->where('status', '=', 1)
->postChannels()
->take(2)
->get(); 
Last updated 3 weeks ago.
0

@gpluess Thanks man! I'll try that to see what difference it'll make because the tweaked query that I posted above gives me the records that I need.

Last updated 3 weeks ago.
0

Sign in to participate in this thread!

Cloudways

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.