first(); abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User'); if ($request->ajax()) { $data = Category::all(); return DataTables::of($data)->addIndexColumn() ->addColumn('action', function($row) use ($menu) { $btn = '
'; if(Gate::allows('update', $menu)) { $btn .= ''; } if(Gate::allows('delete', $menu)) { $btn .= ''; } $btn .= '
'; return $btn; }) ->rawColumns(['action']) ->make(true); } return view('back.master.category'); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $menu = Menu::where('link', 'category.index')->first(); abort_if(Gate::denies('create', $menu), 403, 'Unauthorized User'); Category::create($request->all()); $response = [ "status" => 200, "message" => "Data created successfully" ]; return response()->json($response); } /** * Display the specified resource. * * @param \App\Models\Category $category * @return \Illuminate\Http\Response */ public function show(Category $category) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\Category $category * @return \Illuminate\Http\Response */ public function edit(Category $category) { $menu = Menu::where('link', 'category.index')->first(); abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User'); $category = Category::find($category->id); $response = [ 'data' => $category, 'status' => 200, 'message' => 'get data successfully' ]; return response()->json($response); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Category $category * @return \Illuminate\Http\Response */ public function update(Request $request, Category $category) { $menu = Menu::where('link', 'category.index')->first(); abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User'); Category::find($category->id)->update($request->all()); $response = [ "status" => 200, "message" => "Data updated successfully" ]; return response()->json($response); } /** * Remove the specified resource from storage. * * @param \App\Models\Category $category * @return \Illuminate\Http\Response */ public function destroy(Category $category) { $menu = Menu::where('link', 'category.index')->first(); abort_if(Gate::denies('delete', $menu), 403, 'Unauthorized User'); Category::destroy($category->id); $response = [ "status" => 200, "message" => "Data deleted successfully" ]; return response()->json($response); } }