fix harga
This commit is contained in:
parent
07aac28e8a
commit
fb8236daf3
@ -26,7 +26,7 @@ class TemplateController extends Controller
|
||||
'kategori_id' => 'required|exists:kategoris,id',
|
||||
'fitur_id' => 'required|exists:fiturs,id',
|
||||
'foto' => 'nullable|image|mimes:jpg,jpeg,png,gif|max:5120',
|
||||
'harga' => 'required|numeric',
|
||||
'harga' => 'required|numeric|min:0'
|
||||
]);
|
||||
|
||||
if ($request->hasFile('foto')) {
|
||||
@ -44,7 +44,7 @@ class TemplateController extends Controller
|
||||
'kategori_id' => 'required|exists:kategoris,id',
|
||||
'fitur_id' => 'required|exists:fiturs,id',
|
||||
'foto' => 'nullable|image|mimes:jpg,jpeg,png,gif|max:5120',
|
||||
'harga' => 'required|numeric',
|
||||
'harga' => 'required|numeric|min:0'
|
||||
]);
|
||||
|
||||
if ($request->hasFile('foto')) {
|
||||
@ -77,6 +77,6 @@ class TemplateController extends Controller
|
||||
$kategoris = Kategori::all();
|
||||
$fiturs = Fitur::all();
|
||||
|
||||
return view('admin.templates.index', compact('templates', 'kategoris', 'fiturs', 'kategori', 'harga'));
|
||||
return view('admin.templates.index', compact('templates', 'kategoris', 'fiturs', 'kategori'));
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Template extends Model
|
||||
{
|
||||
protected $fillable = ['nama_template', 'kategori_id', 'fitur_id', 'foto'];
|
||||
protected $fillable = ['nama_template', 'kategori_id', 'fitur_id', 'foto', 'harga'];
|
||||
|
||||
public function kategori() {
|
||||
return $this->belongsTo(Kategori::class);
|
||||
|
@ -12,6 +12,7 @@ return new class extends Migration {
|
||||
$table->string('nama_template');
|
||||
$table->foreignId('kategori_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('fitur_id')->constrained()->cascadeOnDelete();
|
||||
$table->decimal('harga', 10, 2)->default(0);
|
||||
$table->string('foto')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
@ -3,7 +3,7 @@
|
||||
@section('title', 'Manajemen Template')
|
||||
|
||||
@section('content')
|
||||
<div class="container mx-auto py-4">
|
||||
<div class="container mx-auto py-4">
|
||||
<!-- Header -->
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<h3 class="text-xl font-bold">
|
||||
@ -26,9 +26,7 @@
|
||||
<div id="toast-success" class="mb-4 p-3 rounded bg-green-100 text-green-800 border border-green-300 shadow">
|
||||
{{ session('success') }}
|
||||
</div>
|
||||
<script>
|
||||
setTimeout(() => document.getElementById('toast-success')?.remove(), 3000);
|
||||
</script>
|
||||
<script>setTimeout(() => document.getElementById('toast-success')?.remove(), 3000);</script>
|
||||
@endif
|
||||
|
||||
@if ($errors->any())
|
||||
@ -39,9 +37,7 @@
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
setTimeout(() => document.getElementById('toast-error')?.remove(), 5000);
|
||||
</script>
|
||||
<script>setTimeout(() => document.getElementById('toast-error')?.remove(), 5000);</script>
|
||||
@endif
|
||||
|
||||
<!-- Tabel Template -->
|
||||
@ -55,6 +51,7 @@
|
||||
<th class="p-2 border border-gray-300 w-[150px]">Kategori</th>
|
||||
<th class="p-2 border border-gray-300 w-[150px]">Fitur</th>
|
||||
<th class="p-2 border border-gray-300 w-[90px] text-center">Foto</th>
|
||||
<th class="p-2 border border-gray-300 w-[100px] text-center">Harga</th>
|
||||
<th class="p-2 border border-gray-300 w-[130px] text-center">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -64,15 +61,16 @@
|
||||
<td class="p-2 border border-gray-300 text-center">{{ $key + 1 }}</td>
|
||||
<td class="p-2 border border-gray-300 truncate">{{ $template->nama_template }}</td>
|
||||
<td class="p-2 border border-gray-300 truncate">{{ $template->kategori->nama ?? '-' }}</td>
|
||||
<td class="p-2 border border-gray-300 truncate">{{ $template->fitur->deskripsi ?? '-' }}
|
||||
</td>
|
||||
<td class="p-2 border border-gray-300 truncate">{{ $template->fitur->deskripsi ?? '-' }}</td>
|
||||
<td class="p-2 border border-gray-300 text-center">
|
||||
<div
|
||||
class="w-12 h-12 overflow-hidden rounded bg-gray-100 flex items-center justify-center mx-auto">
|
||||
<div class="w-12 h-12 overflow-hidden rounded bg-gray-100 flex items-center justify-center mx-auto">
|
||||
<img src="{{ $template->foto ? asset('storage/' . $template->foto) : asset('default-image.png') }}"
|
||||
alt="foto" class="max-w-full max-h-full object-contain">
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-2 border border-gray-300 text-right font-semibold">
|
||||
Rp {{ number_format($template->harga, 0, ',', '.') }}
|
||||
</td>
|
||||
<td class="p-2 border border-gray-300 text-center">
|
||||
<div class="flex justify-center space-x-2">
|
||||
<button class="text-blue-600 hover:underline flex items-center openEditModalBtn"
|
||||
@ -92,15 +90,13 @@
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="6" class="p-2 text-center text-gray-500 border border-gray-300">Belum ada
|
||||
template</td>
|
||||
<td colspan="7" class="p-2 text-center text-gray-500 border border-gray-300">Belum ada template</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Tambah Template -->
|
||||
@if (!isset($kategori))
|
||||
@ -133,6 +129,10 @@
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Harga</label>
|
||||
<input type="number" name="harga" class="w-full p-2 border rounded" required min="0" step="1000">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Foto (opsional)</label>
|
||||
<input type="file" name="foto" class="w-full p-2 border rounded" accept="image/*">
|
||||
@ -140,8 +140,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4 border-t flex justify-end space-x-2">
|
||||
<button type="button" id="closeTambahBtn"
|
||||
class="bg-gray-300 text-black px-3 py-1 rounded">Batal</button>
|
||||
<button type="button" id="closeTambahBtn" class="bg-gray-300 text-black px-3 py-1 rounded">Batal</button>
|
||||
<button class="bg-blue-600 text-white px-3 py-1 rounded">Simpan</button>
|
||||
</div>
|
||||
</form>
|
||||
@ -169,8 +168,7 @@
|
||||
<label class="block text-sm font-medium">Kategori</label>
|
||||
<select name="kategori_id" class="w-full p-2 border rounded" required>
|
||||
@foreach ($kategoris as $kategori)
|
||||
<option value="{{ $kategori->id }}" @selected($kategori->id == $template->kategori_id)>{{ $kategori->nama }}
|
||||
</option>
|
||||
<option value="{{ $kategori->id }}" @selected($kategori->id == $template->kategori_id)>{{ $kategori->nama }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@ -178,18 +176,21 @@
|
||||
<label class="block text-sm font-medium">Fitur</label>
|
||||
<select name="fitur_id" class="w-full p-2 border rounded" required>
|
||||
@foreach ($fiturs as $fitur)
|
||||
<option value="{{ $fitur->id }}" @selected($fitur->id == $template->fitur_id)>
|
||||
{{ $fitur->deskripsi }}</option>
|
||||
<option value="{{ $fitur->id }}" @selected($fitur->id == $template->fitur_id)>{{ $fitur->deskripsi }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Harga</label>
|
||||
<input type="number" name="harga" value="{{ $template->harga }}"
|
||||
class="w-full p-2 border rounded" required min="0" step="1000">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Foto (opsional)</label>
|
||||
@if ($template->foto)
|
||||
<div class="mb-2">
|
||||
<small class="text-gray-500">Foto saat ini:</small>
|
||||
<div
|
||||
class="w-20 h-20 mt-1 overflow-hidden rounded bg-gray-100 flex items-center justify-center border">
|
||||
<div class="w-20 h-20 mt-1 overflow-hidden rounded bg-gray-100 flex items-center justify-center border">
|
||||
<img src="{{ asset('storage/' . $template->foto) }}" alt="foto"
|
||||
class="max-w-full max-h-full object-contain">
|
||||
</div>
|
||||
@ -274,4 +275,5 @@
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
@endsection
|
||||
|
Loading…
Reference in New Issue
Block a user