'Barbershop', 'barbershop' => Barbershop::latest()->get(), ]); } public function create(): View { return view('pages.admin.master.barbershop.create', [ 'pageTitle' => 'Tambah Barbershop', ]); } public function store(BarbershopRequest $request): RedirectResponse { $validatedData = $request->validated(); DB::transaction(function () use ($validatedData) { $newBarbershop = Barbershop::create($validatedData); $this->uploadAttachment($validatedData['image'], 'barbershop', Barbershop::class, $newBarbershop->id); }); notify()->success('Data berhasil ditambahkan', 'Berhasil'); return redirect('dashboard/master/barbershop'); } public function edit(Barbershop $barbershop): View { return view('pages.admin.master.barbershop.edit', [ 'pageTitle' => 'Edit Barbershop', 'barbershop' => $barbershop, ]); } public function update(Barbershop $barbershop, BarbershopRequest $request): RedirectResponse { $validatedData = $request->validated(); DB::transaction(function () use ($barbershop, $validatedData) { $barbershop->update($validatedData); $this->uploadAttachment($validatedData['image'], 'barbershop', Barbershop::class, $barbershop->id); }); notify()->success('Data berhasil ditambahkan', 'Berhasil'); return redirect('dashboard/master/barbershop'); } public function delete(Barbershop $barbershop): RedirectResponse { if (Auth::user()->barbershop_id === $barbershop->id) { notify()->info('Anda sedang berada di barbershop ini, silakan pilih barbershop lain lalu Anda dapat menghapusnya', 'Informasi'); return back(); } $barbershop->delete(); notify()->success('Data berhasil dihapus', 'Berhasil'); return redirect('dashboard/master/barbershop'); } public function generateActionButtons(Barbershop $barbershop): string { $editUrl = route('master.barbershop.edit', encryptId($barbershop->id)); $deleteUrl = route('master.barbershop.delete', encryptId($barbershop->id)); return '
'; } }