Last active
August 29, 2015 14:11
-
-
Save 0xMatt/4ef87fff88c658b7f109 to your computer and use it in GitHub Desktop.
Get paginated relationship results for Eloquent 4&5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Controller { | |
public function action() | |
{ | |
$model = MyModal::with('relationship')->first(); | |
return $model->relationshipPaginated(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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