Edit user PIREP
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Requests\CreatePirepRequest;
|
||||
use App\Http\Requests\UpdatePirepRequest;
|
||||
use App\Repositories\AircraftRepository;
|
||||
use App\Repositories\AirlineRepository;
|
||||
use App\Repositories\AirportRepository;
|
||||
use App\Repositories\PirepRepository;
|
||||
use App\Services\PIREPService;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -12,16 +14,26 @@ use Flash;
|
||||
use Log;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
use Response;
|
||||
use App\Facades\Utils;
|
||||
|
||||
|
||||
class PirepController extends BaseController
|
||||
{
|
||||
private $pirepRepo, $aircraftRepo, $pirepSvc;
|
||||
private $airportRepo,
|
||||
$airlineRepo,
|
||||
$pirepRepo,
|
||||
$aircraftRepo,
|
||||
$pirepSvc;
|
||||
|
||||
public function __construct(
|
||||
AirportRepository $airportRepo,
|
||||
AirlineRepository $airlineRepo,
|
||||
AircraftRepository $aircraftRepo,
|
||||
PirepRepository $pirepRepo,
|
||||
PIREPService $pirepSvc
|
||||
) {
|
||||
$this->airportRepo = $airportRepo;
|
||||
$this->airlineRepo = $airlineRepo;
|
||||
$this->aircraftRepo = $aircraftRepo;
|
||||
$this->pirepRepo = $pirepRepo;
|
||||
$this->pirepSvc = $pirepSvc;
|
||||
@@ -128,15 +140,20 @@ class PirepController extends BaseController
|
||||
public function edit($id)
|
||||
{
|
||||
$pirep = $this->pirepRepo->findWithoutFail($id);
|
||||
|
||||
if (empty($pirep)) {
|
||||
Flash::error('Pirep not found');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
}
|
||||
|
||||
$hms = Utils::secondsToTimeParts($pirep->flight_time);
|
||||
$pirep->hours = $hms['h'];
|
||||
$pirep->minutes = $hms['m'];
|
||||
|
||||
return view('admin.pireps.edit', [
|
||||
'pirep' => $pirep,
|
||||
'aircraft' => $this->aircraftList(),
|
||||
'airports' => $this->airportRepo->selectBoxList(),
|
||||
'airlines' => $this->airlineRepo->selectBoxList(),
|
||||
'aircraft' => $this->aircraftRepo->selectBoxList(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -150,6 +167,9 @@ class PirepController extends BaseController
|
||||
{
|
||||
$pirep = $this->pirepRepo->findWithoutFail($id);
|
||||
|
||||
$pirep->flight_time = ((int)$request['hours'] * 60 * 60)
|
||||
+ ((int)$request['minutes'] * 60);
|
||||
|
||||
if (empty($pirep)) {
|
||||
Flash::error('Pirep not found');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Frontend;
|
||||
|
||||
use App\Services\PIREPService;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -22,29 +23,31 @@ class PirepController extends Controller
|
||||
$aircraftRepo,
|
||||
$pirepRepo,
|
||||
$airportRepo,
|
||||
$pirepFieldRepo;
|
||||
$pirepFieldRepo,
|
||||
$pirepSvc;
|
||||
|
||||
public function __construct(
|
||||
AirlineRepository $airlineRepo,
|
||||
PirepRepository $pirepRepo,
|
||||
AircraftRepository $aircraftRepo,
|
||||
AirportRepository $airportRepo,
|
||||
PirepFieldRepository $pirepFieldRepo
|
||||
PirepFieldRepository $pirepFieldRepo,
|
||||
PIREPService $pirepSvc
|
||||
) {
|
||||
$this->airlineRepo = $airlineRepo;
|
||||
$this->aircraftRepo = $aircraftRepo;
|
||||
$this->pirepRepo = $pirepRepo;
|
||||
$this->airportRepo = $airportRepo;
|
||||
$this->pirepFieldRepo = $pirepFieldRepo;
|
||||
$this->pirepSvc = $pirepSvc;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$pireps = $this->pirepRepo
|
||||
->where('user_id', $user->id)
|
||||
$pireps = Pirep::where('user_id', $user->id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
->paginate();
|
||||
|
||||
return $this->view('pireps.index', [
|
||||
'user' => $user,
|
||||
@@ -54,11 +57,9 @@ class PirepController extends Controller
|
||||
|
||||
public function create()
|
||||
{
|
||||
$aircraft = $this->aircraftList();
|
||||
|
||||
return $this->view('pireps.create', [
|
||||
'airports' => $this->airportRepo->selectBoxList(),
|
||||
'airlines' => $this->airlineRepo->all()->pluck('name', 'id'),
|
||||
'airlines' => $this->airlineRepo->selectBoxList(),
|
||||
'aircraft' => $this->aircraftRepo->selectBoxList(),
|
||||
'pirepfields' => $this->pirepFieldRepo->all(),
|
||||
'fieldvalues' => [],
|
||||
@@ -95,8 +96,7 @@ class PirepController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
$pirepSvc = app('\App\Services\PIREPService');
|
||||
$pirep = $pirepSvc->create($pirep, $custom_fields);
|
||||
$pirep = $this->pirepSvc->create($pirep, $custom_fields);
|
||||
|
||||
//Flash::success('PIREP submitted successfully!');
|
||||
return redirect(route('frontend.pireps.index'));
|
||||
|
||||
Reference in New Issue
Block a user