2018-02-28 04:12:03 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Service;
|
2018-03-24 03:10:18 +08:00
|
|
|
use App\Models\Flight;
|
2018-02-28 04:12:03 +08:00
|
|
|
use App\Models\Rank;
|
|
|
|
use App\Models\Subfleet;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class FleetService
|
|
|
|
*/
|
|
|
|
class FleetService extends Service
|
2018-02-28 04:12:03 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param Subfleet $subfleet
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param Rank $rank
|
|
|
|
* @param array $overrides
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-28 04:12:03 +08:00
|
|
|
* @return Subfleet
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function addSubfleetToRank(Subfleet $subfleet, Rank $rank, array $overrides = [])
|
2018-02-28 04:12:03 +08:00
|
|
|
{
|
|
|
|
$subfleet->ranks()->syncWithoutDetaching([$rank->id]);
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($overrides) {
|
2018-02-28 04:12:03 +08:00
|
|
|
$subfleet->ranks()->updateExistingPivot($rank->id, $overrides);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subfleet->save();
|
|
|
|
$subfleet->refresh();
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-02-28 04:12:03 +08:00
|
|
|
return $subfleet;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeSubfleetFromRank(Subfleet $subfleet, Rank $rank)
|
|
|
|
{
|
|
|
|
$subfleet->ranks()->detach($rank->id);
|
|
|
|
|
|
|
|
$subfleet->save();
|
|
|
|
$subfleet->refresh();
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-02-28 04:12:03 +08:00
|
|
|
return $subfleet;
|
|
|
|
}
|
2018-03-24 03:10:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the subfleet to a flight
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-24 03:10:18 +08:00
|
|
|
* @param Subfleet $subfleet
|
|
|
|
* @param Flight $flight
|
|
|
|
*/
|
|
|
|
public function addSubfleetToFlight(Subfleet $subfleet, Flight $flight)
|
|
|
|
{
|
|
|
|
$flight->subfleets()->syncWithoutDetaching([$subfleet->id]);
|
|
|
|
$subfleet->save();
|
|
|
|
$subfleet->refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the subfleet from a flight
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-24 03:10:18 +08:00
|
|
|
* @param Subfleet $subfleet
|
|
|
|
* @param Flight $flight
|
|
|
|
*/
|
|
|
|
public function removeSubfleetFromFlight(Subfleet $subfleet, Flight $flight)
|
|
|
|
{
|
|
|
|
$flight->subfleets()->detach($subfleet->id);
|
|
|
|
}
|
2018-02-28 04:12:03 +08:00
|
|
|
}
|