138 lines
3.6 KiB
PHP
138 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Guide;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Http\Request;
|
|
|
|
class GuideController extends Controller
|
|
{
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware([ "auth" ]);
|
|
$this->middleware([ "lang" ]);
|
|
|
|
$this->middleware([ "check.auth:guides.list" ])->only("index");
|
|
$this->middleware([ "check.auth:guides.show" ])->only("show");
|
|
$this->middleware([ "check.auth:guides.create" ])->only("create", "store");
|
|
$this->middleware([ "check.auth:guides.edit" ])->only("edit", "update");
|
|
$this->middleware([ "check.auth:guides.delete" ])->only("delete");
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$guides = Guide::query()->paginate($request->input("limit", 20));
|
|
|
|
return Response::detect("guides.index", [ "guides" => $guides]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return Response::detect("guides.create");
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
|
|
//Me no sure what to store mester big smoke :)
|
|
$requestGuide = $request->validate([
|
|
"name" => "required|max:255",
|
|
"guide_articles" => "required",
|
|
]);
|
|
|
|
$guide = new Guide($requestGuide);
|
|
$saved = $guide->save();
|
|
|
|
if(!$saved){
|
|
return redirect()->route("guides.store");
|
|
}else{
|
|
$guide = Guide::query()->paginate($request->input("limit", 20));
|
|
return redirect()->route("guides.index", ['guides' => $guide]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param \App\Guide $guide
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(Guide $guide)
|
|
{
|
|
return Response::detect("guides.show", [ "guide" => $guide]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Guide $guide
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(Guide $guide)
|
|
{
|
|
$guidee = Guide::query()->where("id", "=", $guide->id)->first();
|
|
return Response::detect("guides.edit", ["guide" => $guidee]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \App\Guide $guide
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, Guide $guide)
|
|
{
|
|
$data = $request->validate([
|
|
"name" => "required|max:255",
|
|
"guide_articles" => "required",
|
|
]);
|
|
|
|
$guidee = Guide::query()->where("id", "=", $guide->id)->first();
|
|
$guidee->update($data);
|
|
$saved = $guidee->save();
|
|
|
|
if(!$saved){
|
|
return redirect()->route("guides.update", [ "guide" => $guide ]);
|
|
}else{
|
|
$guide = Guide::query()->paginate($request->input("limit", 20));
|
|
return redirect()->route("guides.index", ['guides' => $guide]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param Guide $guide
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($guide)
|
|
{
|
|
$guide = Guide::find($guide);
|
|
$guide->delete();
|
|
|
|
return redirect()->route("guides.index");
|
|
}
|
|
}
|