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-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
|
|
|
|
* @package App\Services
|
|
|
|
*/
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
}
|