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

140 lines
3.6 KiB
PHP
Raw Normal View History

<?php
2017-06-11 11:17:45 +08:00
namespace App\Http\Controllers\Admin;
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;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;
2017-06-11 11:17:45 +08:00
class FareController extends BaseController
{
/** @var FareRepository */
private $fareRepository;
2018-02-21 12:33:09 +08:00
/**
* FareController constructor.
* @param FareRepository $fareRepo
*/
public function __construct(
FareRepository $fareRepo
) {
$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
*/
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
*/
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
* @param UpdateFareRequest $request
* @return Response
2018-02-21 12:33:09 +08:00
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
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
$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
$this->fareRepository->delete($id);
Flash::success('Fare deleted successfully.');
return redirect(route('admin.fares.index'));
}
}