[Add Kategori]
Belum View
This commit is contained in:
parent
f38f8a286f
commit
acc32b08ca
64
backend/app/Http/Controllers/KategoriController.php
Normal file
64
backend/app/Http/Controllers/KategoriController.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
use App\Models\Kategori;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
class KategoriController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return response()->json(Kategori::all(), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(Kategori $kategori)
|
||||||
|
{
|
||||||
|
return response()->json($kategori, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'nama' => 'required',
|
||||||
|
'deskripsi' => 'nullable',
|
||||||
|
'foto' => 'nullable|image|mimes:jpg,jpeg,png|max:2048'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = $request->all();
|
||||||
|
if ($request->hasFile('foto')) {
|
||||||
|
$data['foto'] = $request->file('foto')->store('kategori', 'public');
|
||||||
|
}
|
||||||
|
|
||||||
|
$kategori = Kategori::create($data);
|
||||||
|
|
||||||
|
return response()->json($kategori, 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, Kategori $kategori)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'nama' => 'required',
|
||||||
|
'deskripsi' => 'nullable',
|
||||||
|
'foto' => 'nullable|image|mimes:jpg,jpeg,png|max:2048'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = $request->all();
|
||||||
|
if ($request->hasFile('foto')) {
|
||||||
|
if ($kategori->foto) Storage::disk('public')->delete($kategori->foto);
|
||||||
|
$data['foto'] = $request->file('foto')->store('kategori', 'public');
|
||||||
|
}
|
||||||
|
|
||||||
|
$kategori->update($data);
|
||||||
|
|
||||||
|
return response()->json($kategori, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Kategori $kategori)
|
||||||
|
{
|
||||||
|
if ($kategori->foto) Storage::disk('public')->delete($kategori->foto);
|
||||||
|
$kategori->delete();
|
||||||
|
|
||||||
|
return response()->json(['message' => 'Kategori berhasil dihapus'], 200);
|
||||||
|
}
|
||||||
|
}
|
18
backend/app/Models/Kategori.php
Normal file
18
backend/app/Models/Kategori.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Kategori extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = ['nama', 'deskripsi', 'foto'];
|
||||||
|
|
||||||
|
public function templates()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Template::class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// database/migrations/xxxx_xx_xx_create_kategoris_table.php
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration {
|
||||||
|
public function up(): void {
|
||||||
|
Schema::create('kategoris', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('nama');
|
||||||
|
$table->text('deskripsi')->nullable();
|
||||||
|
$table->string('foto')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void {
|
||||||
|
Schema::dropIfExists('kategoris');
|
||||||
|
}
|
||||||
|
};
|
@ -74,7 +74,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h4 class="text-center mb-2 fw-bold">SELAMAT DATANG</h4>
|
<h4 class="text-center mb-2 fw-bold">SELAMAT DATANG</h4>
|
||||||
<p class="text-center text-muted mb-4">Selamat datang! Silakan masukkan detail Anda.</p>
|
<p class="text-center text-muted mb-4">Silakan masukkan email dan password anda.</p>
|
||||||
|
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
|
@ -3,19 +3,105 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Admin Dashboard</title>
|
<title>Halaman Dasbor</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
.dashboard-card {
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
|
||||||
|
padding: 20px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
.dashboard-card h5 {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #6c757d;
|
||||||
|
}
|
||||||
|
.dashboard-card h3 {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.dashboard-icon {
|
||||||
|
font-size: 28px;
|
||||||
|
color: #0d6efd;
|
||||||
|
background: #eef4ff;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
.date-box {
|
||||||
|
background: #eef4ff;
|
||||||
|
color: #0d6efd;
|
||||||
|
padding: 6px 12px;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="p-4">
|
<body class="p-4">
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<!-- Header -->
|
||||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
<h3>Admin Dashboard</h3>
|
<h3 class="fw-bold">Halaman Dasbor</h3>
|
||||||
<form action="{{ route('admin.logout') }}" method="POST">
|
|
||||||
@csrf
|
<div class="d-flex align-items-center gap-3">
|
||||||
<button class="btn btn-outline-danger">Logout</button>
|
<div class="date-box">
|
||||||
</form>
|
<i class="bi bi-clock-history"></i>
|
||||||
|
{{ \Carbon\Carbon::now()->translatedFormat('l, d F Y') }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Logout -->
|
||||||
|
<form action="{{ route('admin.logout') }}" method="POST" class="m-0">
|
||||||
|
@csrf
|
||||||
|
<button class="btn btn-outline-danger">Logout</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Cards -->
|
||||||
|
<div class="row g-4">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="dashboard-card">
|
||||||
|
<div>
|
||||||
|
<h5>Kategori</h5>
|
||||||
|
<h3>10</h3>
|
||||||
|
</div>
|
||||||
|
<i class="bi bi-diagram-3 dashboard-icon"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="dashboard-card">
|
||||||
|
<div>
|
||||||
|
<h5>Templat</h5>
|
||||||
|
<h3>20</h3>
|
||||||
|
</div>
|
||||||
|
<i class="bi bi-card-list dashboard-icon"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="dashboard-card">
|
||||||
|
<div>
|
||||||
|
<h5>Pelanggan</h5>
|
||||||
|
<h3>24</h3>
|
||||||
|
</div>
|
||||||
|
<i class="bi bi-person dashboard-icon"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pesan login -->
|
||||||
|
<div class="alert alert-success mt-4">
|
||||||
|
Berhasil login sebagai <strong>{{ auth('admin')->user()->name }}</strong>
|
||||||
</div>
|
</div>
|
||||||
<div class="alert alert-success">Berhasil login sebagai <strong>{{ auth('admin')->user()->name }}</strong></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user