cms/app/Repositories/PostRepository.php

28 lines
605 B
PHP

<?php
namespace App\Repositories;
use App\Post;
use Illuminate\Pagination\LengthAwarePaginator;
class PostRepository extends BaseRepository
{
public function __construct($model)
{
if(is_string($model)) {
$this->setModel(app($model));
} elseif($model instanceof Post) {
$this->setModel($model);
}
}
/**
* @param int $postsPerPage
* @return LengthAwarePaginator
*/
public function getPostsPager($postsPerPage = 15)
{
return $this->getModelClass()::orderByDesc('created_at')->paginate($postsPerPage);
}
}