fieldRepository = $fieldRepository; $this->dropdownRepository = $dropdownRepository; } /** * Display a listing of the resource. */ public function index() { $data['title'] = 'Dropdown List'; $data['fields'] = $this->fieldRepository->findAll(); $data['fieldLists'] = $data['fields']->pluck('title', 'id'); return view('admin::dropdown.index', $data); } /** * Show the form for creating a new resource. */ public function create() { return view('admin::create'); } /** * Store a newly created resource in storage. */ public function store(Request $request): RedirectResponse { $inputData = $request->all(); try { // $inputData['status'] = $request->status ?? 10; $this->dropdownRepository->create($inputData); toastr()->success('Dropdown Created Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return redirect()->route('dropdown.index'); } /** * Show the specified resource. */ public function show($id) { return view('admin::show'); } /** * Show the form for editing the specified resource. */ public function edit($id) { $dropdownModel = $this->dropdownRepository->getDropdownById($id); $fieldLists = $this->fieldRepository->getList(); return response()->json([ 'view' => view('admin::dropdown.edit', compact('dropdownModel', 'fieldLists'))->render(), 'status' => true, ]); } /** * Update the specified resource in storage. */ public function update(Request $request, $id): RedirectResponse { $inputData = $request->except(['_method', '_token']); try { $inputData['status'] = $request->status ?? 10; $this->dropdownRepository->update($id, $inputData); toastr()->success('Dropdown Update Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return redirect()->route('dropdown.index'); } /** * Remove the specified resource from storage. */ public function destroy($id) { try { $this->dropdownRepository->delete($id); toastr()->success('Dropdown Deleted Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return response()->json([ 'status' => true, ]); } }