Skip to content

Instantly share code, notes, and snippets.

@0xMatt
Last active August 29, 2015 14:11
Show Gist options
  • Save 0xMatt/4ef87fff88c658b7f109 to your computer and use it in GitHub Desktop.
Save 0xMatt/4ef87fff88c658b7f109 to your computer and use it in GitHub Desktop.
Get paginated relationship results for Eloquent 4&5
<?php
class Controller {
public function action()
{
$model = MyModal::with('relationship')->first();
return $model->relationshipPaginated();
}
}
<?php
use Illuminate\Database\Eloqunt\Model;
class MyModal exttends Model {
public function getRelationshipPaginatedAttribute()
{
// Laravel 5
return new Paginator($this->relationship->toArray(), 10);
// Laravel 4
return Paginator::make($this->relationship->toARray(), 10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment