dimanche 18 septembre 2016

Why is SimplePaginate Function failed to work here?

The Function simplePaginate() is working after calling the where() Function directly like that :

$posts = $userA->Posts()->simplePaginate(10)->get();

The Posts() Function in the User Eloquent:

public function Posts(){
  return Post::where('user_id','$this->id')->where('category','programming');
}

For yet everything is working fine but the problem is when I have more than a user, So I made this :

//Creating Empty Collection (Working Without any problem)
$posts = new \Illuminate\Database\Eloquent\Collection;

//Getting and Adding the userA Posts (Working Without any problem)
$userA_Posts = $userA->Posts();
$posts = $posts->merge($userA_Posts);

//Getting and Adding the userB Posts (Working Without any problem)
$userB_Posts = $userB->Posts();
$posts = $posts->merge($userB_Posts);

//Getting and Adding the userC Posts (Working Without any problem)
$userC_Posts = $userC->Posts();
$posts = $posts->merge($userC_Posts);

//Here Laravel Shows me an ERROR {Method simplePaginate does not exist}
$posts = $posts->sortByDesc('created_at')->simplePaginate(10)->values()->all();

//I changed it to this, ERROR {Method simplePaginate does not exist}
$posts = $posts->sortByDesc('created_at')->values()->simplePaginate(10)->all();

//I changed it to this, ERROR {Method simplePaginate does not exist}
$posts = $posts->sortByDesc('created_at')->values()->all()->simplePaginate(10);

In the laravel Documentation I didn't find the simplePaginate() Function But it's working after the where() Function , So please Help



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire