Flight history #807
This commit is contained in:
@@ -6,7 +6,8 @@ use Illuminate\Validation\Validator;
|
||||
use Prettus\Repository\Eloquent\BaseRepository;
|
||||
|
||||
/**
|
||||
* @mixin \Prettus\Repository\Eloquent\BaseRepository
|
||||
* @mixin Model
|
||||
* @mixin BaseRepository
|
||||
*/
|
||||
abstract class Repository extends BaseRepository
|
||||
{
|
||||
|
||||
@@ -7,9 +7,6 @@ use App\Models\Enums\PirepState;
|
||||
use App\Models\Pirep;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Class PirepRepository
|
||||
*/
|
||||
class PirepRepository extends Repository
|
||||
{
|
||||
protected $fieldSearchable = [
|
||||
|
||||
@@ -4,11 +4,13 @@ namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Enums\PirepState;
|
||||
use App\Models\Pirep;
|
||||
use App\Repositories\PirepRepository;
|
||||
|
||||
class AircraftService extends Service
|
||||
{
|
||||
/** @var PirepRepository */
|
||||
private $pirepRepo;
|
||||
|
||||
public function __construct(PirepRepository $pirepRepo)
|
||||
@@ -16,6 +18,26 @@ class AircraftService extends Service
|
||||
$this->pirepRepo = $pirepRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the PIREPs that have been flown by this aircraft
|
||||
*
|
||||
* @param Aircraft $aircraft
|
||||
* @param int $count
|
||||
*
|
||||
* @return Pirep[] Collection of PIREPs
|
||||
*/
|
||||
public function getFlightHistory(Aircraft $aircraft, $count = 5)
|
||||
{
|
||||
return $this->pirepRepo
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit($count)
|
||||
->where([
|
||||
'aircraft_id' => $aircraft->id,
|
||||
'state' => PirepState::ACCEPTED,
|
||||
])
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculate all aircraft stats and hours
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user