$user_details = User::where(''user_name','=',$userName')->skip(0)->take(6)->get();
Skip tells how many of the rows to skip, take shows how many of the rows to take
Sorry it took so long to reply
Oh, and apparently you can probably skip the ->skip(0) unless you need it
Sounds like the has()
method would work better for this situation.
$collectionList = Collection::with(array('items' => function($query)
{
$user_details = User::where('user_name','=',$userName)->first();
$query->where('user_id','=',$user_details->id);
}))->get();
I'm probably wrong...
cryode said:
Sounds like the
has()
method would work better for this situation.
$posts = Collection::whereHas('items', function($q)
{
$q->where('user_id', '=', $user_details->id);
})->get();
Same issue
Solved
Problem 1 Solution public function itemsLimitSix() { return $this->BelongstoMany('Item')->limit(6); }
Problem 2 Solution http://laravel.io/forum/02-08-2014-using-variable-in-db-function-solved
On top of that , i also tested with DB::getQueryLog(); , It's working fine with the Limit in it.
Credit to @rufhausen
I was hoping to see a solution in your thread, but unfortunately I didn't. As you, I wanted to limit the eager loaded results per result. Setting the limit like this public function itemsLimitSix() { return $this->BelongstoMany('Item')->limit(6); }
it is exactly the same as applying the limit in the constraint:
$posts = Collection::whereHas('items', function($q)
{
$q->where('user_id', '=', $user_details->id)->limit(6);
})->get();
This will limit the count of ALL items return to 6, and not to 6 per post as you want. The same problem is asked here: http://stackoverflow.com/questions/16960079/limit-eager-loaded-comments
I would be glad to hear a solution.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community