2020-09-10 13:31:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\GuidesCategory;
|
2020-09-14 06:57:31 +00:00
|
|
|
use App\Guide;
|
2020-09-10 13:31:06 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
|
|
|
class GuidesCategoryController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware([ "auth" ]);
|
|
|
|
$this->middleware([ "lang" ]);
|
|
|
|
|
|
|
|
$this->middleware([ "check.auth:guides.show" ])->only("show", "index");
|
|
|
|
$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.
|
|
|
|
*
|
2020-09-14 06:57:31 +00:00
|
|
|
* @return Response
|
2020-09-10 13:31:06 +00:00
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2020-09-22 08:45:27 +00:00
|
|
|
$guideCate = GuidesCategory::query()->get();
|
2020-09-10 13:31:06 +00:00
|
|
|
return Response::detect("guides-category.index", [ "guidesCategory" => $guideCate]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
return Response::detect("guides-category.create");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$requestGuideCategory = $request->validate([
|
|
|
|
"guidesCategoryName" => "required|max:255",
|
|
|
|
]);
|
|
|
|
|
|
|
|
$guideCate = new GuidesCategory($requestGuideCategory);
|
|
|
|
$saved = $guideCate->save();
|
|
|
|
|
|
|
|
if(!$saved) {
|
|
|
|
return redirect()->route("guides-category.store");
|
|
|
|
} else {
|
2020-09-22 08:45:27 +00:00
|
|
|
$guides = Guide::query()->get();
|
2020-09-10 13:31:06 +00:00
|
|
|
|
|
|
|
return redirect()->route("guides.index", ['guides' => $guides]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2020-09-14 06:57:31 +00:00
|
|
|
* @param int $id
|
2020-09-10 13:31:06 +00:00
|
|
|
*/
|
2020-09-14 06:57:31 +00:00
|
|
|
public function show($id)
|
2020-09-10 13:31:06 +00:00
|
|
|
{
|
2020-09-14 06:57:31 +00:00
|
|
|
return Response::detect("guides-category.show", $id);
|
2020-09-10 13:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2020-09-14 06:57:31 +00:00
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
2020-09-10 13:31:06 +00:00
|
|
|
*/
|
2020-09-14 06:57:31 +00:00
|
|
|
public function edit($id)
|
2020-09-10 13:31:06 +00:00
|
|
|
{
|
2020-09-14 06:57:31 +00:00
|
|
|
$guideCate = GuidesCategory::query()->where("id", "=", $id)->first();
|
|
|
|
return Response::detect("guides-category.edit", [ "guideCategory" => $guideCate]);
|
2020-09-10 13:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2020-09-14 06:57:31 +00:00
|
|
|
* @param int $id
|
2020-09-10 13:31:06 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-09-14 06:57:31 +00:00
|
|
|
public function update(Request $request, $id)
|
2020-09-10 13:31:06 +00:00
|
|
|
{
|
|
|
|
$data = $request->validate([
|
2020-09-11 07:08:07 +00:00
|
|
|
"guidesCategoryName" => "required|max:255",
|
2020-09-10 13:31:06 +00:00
|
|
|
]);
|
|
|
|
|
2020-09-14 06:57:31 +00:00
|
|
|
$guideCate = GuidesCategory::query()->where("id", "=", $id)->first();
|
2020-09-10 13:31:06 +00:00
|
|
|
$guideCate->update($data);
|
|
|
|
$saved = $guideCate->save();
|
|
|
|
|
|
|
|
if(!$saved){
|
2020-09-14 06:57:31 +00:00
|
|
|
return redirect()->route("guides-category.edit", $id);
|
2020-09-10 13:31:06 +00:00
|
|
|
}else{
|
2020-09-22 08:45:27 +00:00
|
|
|
$guides = Guide::query()->get();
|
2020-09-10 13:31:06 +00:00
|
|
|
|
2020-09-14 06:57:31 +00:00
|
|
|
return redirect()->route("guides.index", ['guides' => $guides]);
|
2020-09-10 13:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2020-09-14 06:57:31 +00:00
|
|
|
* @param int $id
|
2020-09-10 13:31:06 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-09-14 06:57:31 +00:00
|
|
|
public function destroy($id)
|
2020-09-10 13:31:06 +00:00
|
|
|
{
|
2020-09-14 06:57:31 +00:00
|
|
|
$guideCategory = GuidesCategory::find($id);
|
|
|
|
$guides = Guide::query()->where('guide_category_id', '=', $id);
|
2020-09-10 13:31:06 +00:00
|
|
|
|
2020-09-14 06:57:31 +00:00
|
|
|
$guides->delete();
|
|
|
|
$guideCategory->delete();
|
2020-09-10 13:31:06 +00:00
|
|
|
|
|
|
|
return redirect()->route("guides.index");
|
|
|
|
}
|
|
|
|
|
2020-09-22 06:56:03 +00:00
|
|
|
//Used for checking if the currently typed Guide Category name is unique. Create version
|
2020-09-10 13:31:06 +00:00
|
|
|
public function nameCheck(Request $request) {
|
|
|
|
$guide = GuidesCategory::query()->where('guidesCategoryName', 'LIKE',$request->nameCheck)->get();
|
|
|
|
if(count($guide) > 0 && $request->nameCheck !== NULL){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 06:56:03 +00:00
|
|
|
//Used for checking if the currently typed Guide Category name is unique. Edit version
|
2020-09-10 13:31:06 +00:00
|
|
|
public function nameCheckUpdate(Request $request) {
|
|
|
|
$guide = GuidesCategory::query()->where('guidesCategoryName', 'LIKE',$request->nameCheck)->where('id', '!=', $request->id)->get();
|
|
|
|
if(count($guide) > 0 && $request->nameCheck !== NULL){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|