2018-01-09 06:22:26 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Repository;
|
2018-01-09 06:22:26 +08:00
|
|
|
use App\Models\News;
|
|
|
|
use Prettus\Repository\Contracts\CacheableInterface;
|
2018-02-21 12:33:09 +08:00
|
|
|
use Prettus\Repository\Traits\CacheableRepository;
|
2018-01-09 06:22:26 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class NewsRepository
|
|
|
|
* @package App\Repositories
|
|
|
|
*/
|
|
|
|
class NewsRepository extends Repository implements CacheableInterface
|
2018-01-09 06:22:26 +08:00
|
|
|
{
|
|
|
|
use CacheableRepository;
|
|
|
|
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return News::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Latest news items
|
|
|
|
* @param int $count
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function getLatest($count = 5)
|
2018-01-09 06:22:26 +08:00
|
|
|
{
|
|
|
|
return $this->orderBy('created_at', 'desc')
|
2018-03-20 09:50:40 +08:00
|
|
|
->with(['user'])
|
|
|
|
->paginate($count);
|
2018-01-09 06:22:26 +08:00
|
|
|
}
|
|
|
|
}
|