delete photo checking rule for edit and delete buket and foto
This commit is contained in:
parent
30df8bbcf7
commit
9560793ff5
|
|
@ -122,7 +122,7 @@ public function update(Request $request, string $id)
|
||||||
|
|
||||||
if ($request->hasFile('foto')) {
|
if ($request->hasFile('foto')) {
|
||||||
// 1. Hapus foto lama jika ada
|
// 1. Hapus foto lama jika ada
|
||||||
if ($buket->foto && file_exists(public_path($buket->foto))) {
|
if ($buket->foto) {
|
||||||
File::delete(public_path($buket->foto));
|
File::delete(public_path($buket->foto));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,7 +142,7 @@ public function destroy(string $id)
|
||||||
{
|
{
|
||||||
$buket = Buket::findOrFail($id);
|
$buket = Buket::findOrFail($id);
|
||||||
|
|
||||||
if ($buket->foto && File::exists(public_path($buket->foto))) {
|
if ($buket->foto) {
|
||||||
File::delete(public_path($buket->foto));
|
File::delete(public_path($buket->foto));
|
||||||
}
|
}
|
||||||
$buket->delete();
|
$buket->delete();
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ public function store(Request $request)
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'nama' => 'required|string|min:3|max:100',
|
'nama' => 'required|string|min:3|max:100',
|
||||||
'harga' => 'required|numeric|min:0',
|
'harga' => 'required|numeric|min:0',
|
||||||
'durasi' => 'required|integer|min:1',
|
'durasi' => 'required|integer|min:0',
|
||||||
'deskripsi' => 'required|string|min:10',
|
'deskripsi' => 'required|string|min:10',
|
||||||
'foto' => 'required|image|mimes:jpeg,png,jpg|max:2048',
|
'foto' => 'required|image|mimes:jpeg,png,jpg|max:2048',
|
||||||
], [
|
], [
|
||||||
|
|
@ -84,7 +84,7 @@ public function update(Request $request, string $id)
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'nama' => 'required|string|min:3|max:100',
|
'nama' => 'required|string|min:3|max:100',
|
||||||
'harga' => 'required|numeric|min:0',
|
'harga' => 'required|numeric|min:0',
|
||||||
'durasi' => 'required|integer|min:1',
|
'durasi' => 'required|integer|min:0',
|
||||||
'deskripsi' => 'required|string|min:10',
|
'deskripsi' => 'required|string|min:10',
|
||||||
'foto' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
'foto' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
||||||
], [
|
], [
|
||||||
|
|
@ -115,7 +115,7 @@ public function update(Request $request, string $id)
|
||||||
|
|
||||||
if ($request->hasFile('foto')) {
|
if ($request->hasFile('foto')) {
|
||||||
// Hapus file lama jika ada foto baru yang diunggah
|
// Hapus file lama jika ada foto baru yang diunggah
|
||||||
if ($paket->foto && File::exists(public_path($paket->foto))) {
|
if ($paket->foto) {
|
||||||
File::delete(public_path($paket->foto));
|
File::delete(public_path($paket->foto));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ public function destroy(string $id)
|
||||||
$paket = PaketFoto::where('id_paket', $id)->firstOrFail();
|
$paket = PaketFoto::where('id_paket', $id)->firstOrFail();
|
||||||
|
|
||||||
// 1. Cek dan hapus file foto dari folder public
|
// 1. Cek dan hapus file foto dari folder public
|
||||||
if ($paket->foto && File::exists(public_path($paket->foto))) {
|
if ($paket->foto) {
|
||||||
File::delete(public_path($paket->foto));
|
File::delete(public_path($paket->foto));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue