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

151 lines
3.5 KiB
PHP
Raw Normal View History

2017-06-22 01:10:25 +08:00
<?php
2017-06-22 02:44:30 +08:00
namespace App\Http\Controllers\Admin;
2017-06-22 01:10:25 +08:00
use App\Http\Requests\CreateRankingRequest;
use App\Http\Requests\UpdateRankingRequest;
2017-06-22 02:44:30 +08:00
use App\Repositories\RankRepository;
2017-06-22 01:10:25 +08:00
use App\Http\Controllers\AppBaseController as InfyOmBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;
2017-06-22 02:44:30 +08:00
class RankController extends BaseController
2017-06-22 01:10:25 +08:00
{
2017-06-22 02:44:30 +08:00
/** @var RankRepository */
private $rankRepository;
2017-06-22 01:10:25 +08:00
2017-06-22 02:44:30 +08:00
public function __construct(RankRepository $rankingRepo)
2017-06-22 01:10:25 +08:00
{
2017-06-22 02:44:30 +08:00
$this->rankRepository = $rankingRepo;
2017-06-22 01:10:25 +08:00
}
/**
* Display a listing of the Ranking.
*
* @param Request $request
* @return Response
*/
public function index(Request $request)
{
2017-06-22 02:44:30 +08:00
$this->rankRepository->pushCriteria(new RequestCriteria($request));
$ranks = $this->rankRepository->all();
2017-06-22 01:10:25 +08:00
2017-06-22 02:44:30 +08:00
return view('admin.ranks.index')
->with('ranks', $ranks);
2017-06-22 01:10:25 +08:00
}
/**
* Show the form for creating a new Ranking.
*
* @return Response
*/
public function create()
{
2017-06-22 02:44:30 +08:00
return view('admin.ranks.create');
2017-06-22 01:10:25 +08:00
}
/**
* Store a newly created Ranking in storage.
*
* @param CreateRankingRequest $request
*
* @return Response
*/
public function store(CreateRankingRequest $request)
{
$input = $request->all();
2017-06-22 02:44:30 +08:00
$rank = $this->rankRepository->create($input);
2017-06-22 01:10:25 +08:00
Flash::success('Ranking saved successfully.');
2017-06-22 02:44:30 +08:00
return redirect(route('admin.ranks.index'));
2017-06-22 01:10:25 +08:00
}
/**
* Display the specified Ranking.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
2017-06-22 02:44:30 +08:00
$rank = $this->rankRepository->findWithoutFail($id);
2017-06-22 01:10:25 +08:00
2017-06-22 02:44:30 +08:00
if (empty($rank)) {
2017-06-22 01:10:25 +08:00
Flash::error('Ranking not found');
2017-06-22 02:44:30 +08:00
return redirect(route('admin.ranks.index'));
2017-06-22 01:10:25 +08:00
}
2017-06-22 02:44:30 +08:00
return view('admin.ranks.show')->with('rank', $rank);
2017-06-22 01:10:25 +08:00
}
/**
* Show the form for editing the specified Ranking.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
{
2017-06-22 02:44:30 +08:00
$rank = $this->rankRepository->findWithoutFail($id);
2017-06-22 01:10:25 +08:00
2017-06-22 02:44:30 +08:00
if (empty($rank)) {
2017-06-22 01:10:25 +08:00
Flash::error('Ranking not found');
2017-06-22 02:44:30 +08:00
return redirect(route('admin.ranks.index'));
2017-06-22 01:10:25 +08:00
}
2017-06-22 02:44:30 +08:00
return view('admin.ranks.edit')->with('rank', $rank);
2017-06-22 01:10:25 +08:00
}
/**
* Update the specified Ranking in storage.
*
* @param int $id
* @param UpdateRankingRequest $request
*
* @return Response
*/
public function update($id, UpdateRankingRequest $request)
{
2017-06-22 02:44:30 +08:00
$rank = $this->rankRepository->findWithoutFail($id);
2017-06-22 01:10:25 +08:00
2017-06-22 02:44:30 +08:00
if (empty($rank)) {
2017-06-22 01:10:25 +08:00
Flash::error('Ranking not found');
2017-06-22 02:44:30 +08:00
return redirect(route('admin.ranks.index'));
2017-06-22 01:10:25 +08:00
}
2017-06-22 02:44:30 +08:00
$rank = $this->rankRepository->update($request->all(), $id);
2017-06-22 01:10:25 +08:00
Flash::success('Ranking updated successfully.');
2017-06-22 02:44:30 +08:00
return redirect(route('admin.ranks.index'));
2017-06-22 01:10:25 +08:00
}
/**
* Remove the specified Ranking from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
{
2017-06-22 02:44:30 +08:00
$rank = $this->rankRepository->findWithoutFail($id);
2017-06-22 01:10:25 +08:00
2017-06-22 02:44:30 +08:00
if (empty($rank)) {
2017-06-22 01:10:25 +08:00
Flash::error('Ranking not found');
2017-06-22 02:44:30 +08:00
return redirect(route('admin.ranks.index'));
2017-06-22 01:10:25 +08:00
}
2017-06-22 02:44:30 +08:00
$this->rankRepository->delete($id);
2017-06-22 01:10:25 +08:00
Flash::success('Ranking deleted successfully.');
2017-06-22 02:44:30 +08:00
return redirect(route('admin.ranks.index'));
2017-06-22 01:10:25 +08:00
}
}