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. * * @return \Illuminate\Http\Response */ public function index() { $guideCate = GuidesCategory::query()->paginate(20); 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 { $guides = GuidesCategory::query()->paginate(20); return redirect()->route("guides.index", ['guides' => $guides]); } } /** * Display the specified resource. * * @param \App\GuidesCategory $guidesCategory * @return \Illuminate\Http\Response */ public function show(GuidesCategory $guidesCategory) { return Response::detect("guides-category.show", [ "guideCategory" => $guidesCategory]); } /** * Show the form for editing the specified resource. * * @param \App\GuidesCategory $guidesCategory * @return \Illuminate\Http\Response */ public function edit(GuidesCategory $guidesCategory) { $guideCate = GuidesCategory::query()->where("id", "=", $guidesCategory->id)->first(); return Response::detect("guides-category.edit", ["guideCategory" => $guideCate]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\GuidesCategory $guidesCategory * @return \Illuminate\Http\Response */ public function update(Request $request, GuidesCategory $guidesCategory) { $data = $request->validate([ "guidesCategoryName" => "required|max:255", ]); $guideCate = Guide::query()->where("id", "=", $guidesCategory->id)->first(); $guideCate->update($data); $saved = $guideCate->save(); if(!$saved){ return redirect()->route("guides-category.update", [ "guideCategory" => $guide ]); }else{ $guides = Guide::query()->paginate(20); return redirect()->route("guides.index", ['guidesCategory' => $guides]); } } /** * Remove the specified resource from storage. * * @param \App\GuidesCategory $guidesCategory * @return \Illuminate\Http\Response */ public function destroy(GuidesCategory $guidesCategory) { $guide = Guide::find($guidesCategory); //$guidesCategory = $id $guide->delete(); return redirect()->route("guides.index"); } public function nameCheck(Request $request) { $guide = GuidesCategory::query()->where('guidesCategoryName', 'LIKE',$request->nameCheck)->get(); if(count($guide) > 0 && $request->nameCheck !== NULL){ return 1; } } 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; } } }