phpvms/app/Repositories/PirepRepository.php

40 lines
888 B
PHP
Raw Normal View History

2017-06-29 08:56:10 +08:00
<?php
namespace App\Repositories;
use App\Models\Pirep;
2017-12-02 00:44:35 +08:00
use App\Models\User;
use Prettus\Repository\Contracts\CacheableInterface;
use Prettus\Repository\Traits\CacheableRepository;
2017-06-29 08:56:10 +08:00
class PirepRepository extends BaseRepository implements CacheableInterface
2017-06-29 08:56:10 +08:00
{
use CacheableRepository;
2017-06-29 08:56:10 +08:00
protected $fieldSearchable = [
'user_id'
];
public function model()
{
return Pirep::class;
}
2017-12-02 00:44:35 +08:00
/**
* Get all the pending reports in order. Returns the Pirep
* model but you still need to call ->all() or ->paginate()
* @param User|null $user
* @return Pirep
*/
public function getPending(User $user=null)
{
$where = [];
if($user !== null) {
$where['user_id'] = $user->id;
}
$pireps = $this->orderBy('created_at', 'desc')->findWhere($where)->all();
return $pireps;
}
2017-06-29 08:56:10 +08:00
}