phpvms/app/Widgets/LatestPireps.php

40 lines
888 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
*/
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,
2018-05-30 00:04:28 +08:00
], 'created_at', 'desc')
->recent($this->config['count']);
return view('widgets.latest_pireps', [
'config' => $this->config,
2018-05-30 00:04:28 +08:00
'pireps' => $pireps,
]);
}
}