phpvms/app/Http/Controllers/Admin/AirlinesController.php

141 lines
3.4 KiB
PHP
Raw Normal View History

2017-06-09 09:02:52 +08:00
<?php
namespace App\Http\Controllers\Admin;
2017-06-20 00:50:25 +08:00
use App\Http\Requests\CreateAirlineRequest;
use App\Http\Requests\UpdateAirlineRequest;
use App\Repositories\AirlineRepository;
2017-06-09 09:02:52 +08:00
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;
2017-06-11 11:17:45 +08:00
class AirlinesController extends BaseController
2017-06-09 09:02:52 +08:00
{
2017-06-20 00:50:25 +08:00
/** @var AirlineRepository */
private $airlineRepo;
2017-06-09 09:02:52 +08:00
2017-06-20 00:50:25 +08:00
public function __construct(AirlineRepository $airlinesRepo)
2017-06-09 09:02:52 +08:00
{
2017-06-20 00:50:25 +08:00
$this->airlineRepo = $airlinesRepo;
2017-06-09 09:02:52 +08:00
}
/**
* Display a listing of the Airlines.
*/
public function index(Request $request)
{
2017-06-20 00:50:25 +08:00
$this->airlineRepo->pushCriteria(new RequestCriteria($request));
$airlines = $this->airlineRepo->all();
2017-06-09 09:02:52 +08:00
return view('admin.airlines.index')
->with('airlines', $airlines);
}
/**
* Show the form for creating a new Airlines.
*/
public function create()
{
return view('admin.airlines.create');
}
/**
* Store a newly created Airlines in storage.
*/
2017-06-20 00:50:25 +08:00
public function store(CreateAirlineRequest $request)
2017-06-09 09:02:52 +08:00
{
$input = $request->all();
2017-06-20 00:50:25 +08:00
$airlines = $this->airlineRepo->create($input);
2017-06-09 09:02:52 +08:00
Flash::success('Airlines saved successfully.');
return redirect(route('admin.airlines.index'));
2017-06-09 09:02:52 +08:00
}
/**
* Display the specified Airlines.
*
* @param int $id
*
2017-06-11 11:17:45 +08:00
* @return mixed
2017-06-09 09:02:52 +08:00
*/
public function show($id)
{
2017-06-20 00:50:25 +08:00
$airlines = $this->airlineRepo->findWithoutFail($id);
2017-06-09 09:02:52 +08:00
if (empty($airlines)) {
Flash::error('Airlines not found');
return redirect(route('admin.airlines.index'));
2017-06-09 09:02:52 +08:00
}
return view('admin.airlines.show')->with('airlines', $airlines);
}
/**
* Show the form for editing the specified Airlines.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
{
2017-11-23 10:03:49 +08:00
$airline = $this->airlineRepo->findWithoutFail($id);
2017-06-09 09:02:52 +08:00
2017-11-23 10:03:49 +08:00
if (empty($airline)) {
Flash::error('Airline not found');
return redirect(route('admin.airlines.index'));
2017-06-09 09:02:52 +08:00
}
2017-11-23 10:03:49 +08:00
return view('admin.airlines.edit')->with('airline', $airline);
2017-06-09 09:02:52 +08:00
}
/**
* Update the specified Airlines in storage.
*
* @param int $id
2017-06-20 00:50:25 +08:00
* @param UpdateAirlineRequest $request
2017-06-09 09:02:52 +08:00
*
* @return Response
*/
2017-06-20 00:50:25 +08:00
public function update($id, UpdateAirlineRequest $request)
2017-06-09 09:02:52 +08:00
{
2017-06-20 00:50:25 +08:00
$airlines = $this->airlineRepo->findWithoutFail($id);
2017-06-09 09:02:52 +08:00
if (empty($airlines)) {
Flash::error('Airlines not found');
return redirect(route('admin.airlines.index'));
2017-06-09 09:02:52 +08:00
}
2017-06-20 00:50:25 +08:00
$airlines = $this->airlineRepo->update($request->all(), $id);
2017-06-09 09:02:52 +08:00
Flash::success('Airlines updated successfully.');
return redirect(route('admin.airlines.index'));
2017-06-09 09:02:52 +08:00
}
/**
* Remove the specified Airlines from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
{
2017-06-20 00:50:25 +08:00
$airlines = $this->airlineRepo->findWithoutFail($id);
2017-06-09 09:02:52 +08:00
if (empty($airlines)) {
Flash::error('Airlines not found');
return redirect(route('admin.airlines.index'));
2017-06-09 09:02:52 +08:00
}
2017-06-20 00:50:25 +08:00
$this->airlineRepo->delete($id);
2017-06-09 09:02:52 +08:00
Flash::success('Airlines deleted successfully.');
return redirect(route('admin.airlines.index'));
2017-06-09 09:02:52 +08:00
}
}