12848091a2
Update to Laravel 9 and PHP 8+ Co-authored-by: B.Fatih KOZ <fatih.koz@gmail.com>
33 lines
772 B
PHP
33 lines
772 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Contracts\Service;
|
|
use App\Models\Aircraft;
|
|
use App\Models\Pirep;
|
|
use App\Repositories\PirepRepository;
|
|
|
|
class AircraftService extends Service
|
|
{
|
|
private PirepRepository $pirepRepo;
|
|
|
|
public function __construct(PirepRepository $pirepRepo)
|
|
{
|
|
$this->pirepRepo = $pirepRepo;
|
|
}
|
|
|
|
/**
|
|
* Recalculate all aircraft stats and hours
|
|
*/
|
|
public function recalculateStats()
|
|
{
|
|
$allAircraft = Aircraft::all(); // TODO: Soft delete
|
|
foreach ($allAircraft as $aircraft) {
|
|
$pirep_time_total = Pirep::where('aircraft_id', $aircraft->id)
|
|
->sum('flight_time');
|
|
$aircraft->flight_time = $pirep_time_total;
|
|
$aircraft->save();
|
|
}
|
|
}
|
|
}
|