country = $country; } /** * Display a listing of the resource. */ public function index(Request $request) { $data['title'] = 'Country List'; $data['countries'] = $this->country->findAll(); if ($request->ajax()) { $model = Country::query(); return DataTables::eloquent($model) ->setRowId('{{$id}}') ->setRowClass('{{"text-center align-middle"}}') ->addColumn('action', 'admin::countries.datatables.action-btn') ->rawColumns(['action']) ->toJson(); } return view('admin::countries.index', $data); } /** * Show the form for creating a new resource. */ public function create() { $data['title'] = 'Create Country'; $data['editable'] = false; return view('admin::countries.create', $data); } /** * Store a newly created resource in storage. */ public function store(Request $request): RedirectResponse { $this->country->create($request->all()); return redirect()->route('country.index'); } /** * Show the specified resource. */ public function show($id) { return view('admin::countries.show'); } /** * Show the form for editing the specified resource. */ public function edit($id) { $data['title'] = 'Edit Country'; $data['editable'] = true; $data['country'] = $this->country->getCountryById($id); return view('admin::countries.edit', $data); } /** * Update the specified resource in storage. */ public function update(Request $request, $id): RedirectResponse { $this->country->update($id, $request->except(['_method', '_token'])); return redirect()->route('country.index'); } /** * Remove the specified resource from storage. */ public function destroy($id) { try { $this->country->delete($id); return response()->json(['status' => 200, 'message' => 'Country has been deleted!'], 200); } catch (\Throwable $th) { return response()->json(['status' => 500, 'message' => 'Country to delete!', 'error' => $th->getMessage()], 500); } } }