[Update Temlete]
This commit is contained in:
parent
0110d6275f
commit
50e9ba339e
@ -27,22 +27,22 @@ class TemplateController extends Controller
|
|||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'nama_template' => 'required|string|max:255',
|
'nama_template' => 'required|string|max:255',
|
||||||
'harga' => 'required|numeric|min:0',
|
'harga' => 'required|numeric|min:0',
|
||||||
'paket' => 'required|in:starter,basic,premium',
|
|
||||||
'foto' => 'nullable|image|mimes:jpg,jpeg,png|max:5120',
|
'foto' => 'nullable|image|mimes:jpg,jpeg,png|max:5120',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// kalau ada upload foto baru
|
// kalau ada upload foto baru
|
||||||
if ($request->hasFile('foto')) {
|
if ($request->hasFile('foto')) {
|
||||||
// hapus foto lama kalau ada
|
|
||||||
if ($template->foto && Storage::exists('public/' . $template->foto)) {
|
if ($template->foto && Storage::exists('public/' . $template->foto)) {
|
||||||
Storage::delete('public/' . $template->foto);
|
Storage::delete('public/' . $template->foto);
|
||||||
}
|
}
|
||||||
|
|
||||||
// simpan foto baru
|
|
||||||
$path = $request->file('foto')->store('templates', 'public');
|
$path = $request->file('foto')->store('templates', 'public');
|
||||||
$validated['foto'] = $path;
|
$validated['foto'] = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pastikan 'paket' tidak diubah
|
||||||
|
$validated['paket'] = $template->paket;
|
||||||
|
|
||||||
$template->update($validated);
|
$template->update($validated);
|
||||||
|
|
||||||
return redirect()->route('admin.template.index')
|
return redirect()->route('admin.template.index')
|
||||||
|
|||||||
@ -52,18 +52,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{-- Paket --}}
|
{{-- Paket --}}
|
||||||
<div>
|
<div class="mb-3">
|
||||||
<label for="paket" class="block text-sm font-medium text-gray-700 mb-2">Paket</label>
|
<label for="paket" class="form-label">Paket</label>
|
||||||
<select id="paket" name="paket"
|
<input type="text" name="paket" id="paket"
|
||||||
class="w-full border border-gray-300 rounded-lg px-4 py-2 bg-gray-50 focus:ring-2 focus:ring-blue-400 focus:outline-none @error('paket') border-red-500 @enderror"
|
value="{{ $template->paket }}"
|
||||||
required>
|
class="form-control"
|
||||||
<option value="starter" {{ old('paket', $template->paket) == 'starter' ? 'selected' : '' }}>Starter</option>
|
readonly>
|
||||||
<option value="basic" {{ old('paket', $template->paket) == 'basic' ? 'selected' : '' }}>Basic</option>
|
|
||||||
<option value="premium" {{ old('paket', $template->paket) == 'premium' ? 'selected' : '' }}>Premium</option>
|
|
||||||
</select>
|
|
||||||
@error('paket')
|
|
||||||
<p class="text-red-500 text-sm mt-1">{{ $message }}</p>
|
|
||||||
@enderror
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{-- Foto / Gambar --}}
|
{{-- Foto / Gambar --}}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user