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