phpvms/app/Widgets/LatestPireps.php

41 lines
928 B
PHP
Raw Normal View History

<?php
namespace App\Widgets;
use App\Contracts\Widget;
2018-05-30 00:04:28 +08:00
use App\Models\Enums\PirepState;
use App\Repositories\PirepRepository;
2018-02-21 12:33:09 +08:00
/**
* Show the latest PIREPs in a view
* sorted nicely by their submit time
2018-02-21 12:33:09 +08:00
*/
class LatestPireps extends Widget
{
protected $config = [
'count' => 5,
];
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function run()
{
$pirepRepo = app(PirepRepository::class);
2018-05-30 00:04:28 +08:00
$pireps = $pirepRepo
2018-09-04 20:02:16 +08:00
->with(['airline', 'aircraft'])
2018-05-30 00:04:28 +08:00
->whereNotInOrder('state', [
PirepState::CANCELLED,
PirepState::DRAFT,
2018-08-27 00:40:04 +08:00
PirepState::IN_PROGRESS,
], 'submitted_at', 'desc')
2018-05-30 00:04:28 +08:00
->recent($this->config['count']);
return view('widgets.latest_pireps', [
'config' => $this->config,
2018-05-30 00:04:28 +08:00
'pireps' => $pireps,
]);
}
}