2017-06-11 07:27:19 +08:00
|
|
|
<?php
|
|
|
|
|
2017-06-11 11:17:45 +08:00
|
|
|
namespace App\Http\Controllers\Admin;
|
2017-06-11 07:27:19 +08:00
|
|
|
|
|
|
|
use App\Http\Requests\CreateFareRequest;
|
|
|
|
use App\Http\Requests\UpdateFareRequest;
|
|
|
|
use App\Repositories\FareRepository;
|
|
|
|
use Flash;
|
2018-02-21 12:33:09 +08:00
|
|
|
use Illuminate\Http\Request;
|
2017-06-11 07:27:19 +08:00
|
|
|
use Prettus\Repository\Criteria\RequestCriteria;
|
|
|
|
use Response;
|
|
|
|
|
2017-06-11 11:17:45 +08:00
|
|
|
class FareController extends BaseController
|
2017-06-11 07:27:19 +08:00
|
|
|
{
|
|
|
|
/** @var FareRepository */
|
|
|
|
private $fareRepository;
|
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
/**
|
|
|
|
* FareController constructor.
|
|
|
|
* @param FareRepository $fareRepo
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
FareRepository $fareRepo
|
|
|
|
) {
|
2017-06-11 07:27:19 +08:00
|
|
|
$this->fareRepository = $fareRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the Fare.
|
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
2018-02-21 12:33:09 +08:00
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
2017-06-11 07:27:19 +08:00
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$this->fareRepository->pushCriteria(new RequestCriteria($request));
|
|
|
|
$fares = $this->fareRepository->all();
|
|
|
|
|
|
|
|
return view('admin.fares.index')
|
|
|
|
->with('fares', $fares);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new Fare.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
return view('admin.fares.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created Fare in storage.
|
|
|
|
* @param CreateFareRequest $request
|
|
|
|
* @return Response
|
2018-02-21 12:33:09 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-11 07:27:19 +08:00
|
|
|
*/
|
|
|
|
public function store(CreateFareRequest $request)
|
|
|
|
{
|
|
|
|
$input = $request->all();
|
|
|
|
$fare = $this->fareRepository->create($input);
|
|
|
|
Flash::success('Fare saved successfully.');
|
|
|
|
|
|
|
|
return redirect(route('admin.fares.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified Fare.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
$fare = $this->fareRepository->findWithoutFail($id);
|
|
|
|
if (empty($fare)) {
|
|
|
|
Flash::error('Fare not found');
|
|
|
|
return redirect(route('admin.fares.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('admin.fares.show')->with('fare', $fare);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified Fare.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$fare = $this->fareRepository->findWithoutFail($id);
|
|
|
|
if (empty($fare)) {
|
|
|
|
Flash::error('Fare not found');
|
|
|
|
return redirect(route('admin.fares.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('admin.fares.edit')->with('fare', $fare);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified Fare in storage.
|
2018-02-21 12:33:09 +08:00
|
|
|
* @param int $id
|
2017-06-11 07:27:19 +08:00
|
|
|
* @param UpdateFareRequest $request
|
|
|
|
* @return Response
|
2018-02-21 12:33:09 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-11 07:27:19 +08:00
|
|
|
*/
|
|
|
|
public function update($id, UpdateFareRequest $request)
|
|
|
|
{
|
|
|
|
$fare = $this->fareRepository->findWithoutFail($id);
|
|
|
|
if (empty($fare)) {
|
|
|
|
Flash::error('Fare not found');
|
|
|
|
return redirect(route('admin.fares.index'));
|
|
|
|
}
|
2017-06-11 11:17:45 +08:00
|
|
|
|
2017-06-11 07:27:19 +08:00
|
|
|
$fare = $this->fareRepository->update($request->all(), $id);
|
|
|
|
Flash::success('Fare updated successfully.');
|
|
|
|
|
|
|
|
return redirect(route('admin.fares.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified Fare from storage.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$fare = $this->fareRepository->findWithoutFail($id);
|
|
|
|
if (empty($fare)) {
|
|
|
|
Flash::error('Fare not found');
|
|
|
|
return redirect(route('admin.fares.index'));
|
|
|
|
}
|
2017-06-11 11:17:45 +08:00
|
|
|
|
2017-06-11 07:27:19 +08:00
|
|
|
$this->fareRepository->delete($id);
|
|
|
|
Flash::success('Fare deleted successfully.');
|
|
|
|
|
|
|
|
return redirect(route('admin.fares.index'));
|
|
|
|
}
|
|
|
|
}
|