[Kategori & Api Ulasan]
done
This commit is contained in:
parent
acc32b08ca
commit
c5486575a3
72
backend/app/Http/Controllers/Api/ReviewController.php
Normal file
72
backend/app/Http/Controllers/Api/ReviewController.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Review;
|
||||||
|
|
||||||
|
class ReviewController extends Controller
|
||||||
|
{
|
||||||
|
// Ambil semua ulasan
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return response()->json(Review::all(), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simpan ulasan baru
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'rating' => 'required|integer|min:1|max:5',
|
||||||
|
'message' => 'required|string',
|
||||||
|
'name' => 'required|string|max:100',
|
||||||
|
'city' => 'required|string|max:100',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$review = Review::create($validated);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Ulasan berhasil disimpan',
|
||||||
|
'data' => $review
|
||||||
|
], 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tampilkan ulasan tertentu
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
$review = Review::findOrFail($id);
|
||||||
|
return response()->json($review, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update ulasan
|
||||||
|
public function update(Request $request, $id)
|
||||||
|
{
|
||||||
|
$review = Review::findOrFail($id);
|
||||||
|
|
||||||
|
$validated = $request->validate([
|
||||||
|
'rating' => 'integer|min:1|max:5',
|
||||||
|
'message' => 'string',
|
||||||
|
'name' => 'string|max:100',
|
||||||
|
'city' => 'string|max:100',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$review->update($validated);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Ulasan berhasil diperbarui',
|
||||||
|
'data' => $review
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hapus ulasan
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$review = Review::findOrFail($id);
|
||||||
|
$review->delete();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Ulasan berhasil dihapus'
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
}
|
18
backend/app/Models/Review.php
Normal file
18
backend/app/Models/Review.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Review extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'rating',
|
||||||
|
'message',
|
||||||
|
'name',
|
||||||
|
'city',
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
<?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('reviews', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->tinyInteger('rating'); // nilai bintang 1–5
|
||||||
|
$table->text('message');
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('city');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('reviews');
|
||||||
|
}
|
||||||
|
};
|
@ -1,5 +1,6 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="id">
|
<html lang="id">
|
||||||
|
|
||||||
<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">
|
||||||
@ -10,22 +11,26 @@
|
|||||||
body {
|
body {
|
||||||
background-color: #f8f9fa;
|
background-color: #f8f9fa;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dashboard-card {
|
.dashboard-card {
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
|
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dashboard-card h5 {
|
.dashboard-card h5 {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #6c757d;
|
color: #6c757d;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dashboard-card h3 {
|
.dashboard-card h3 {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dashboard-icon {
|
.dashboard-icon {
|
||||||
font-size: 28px;
|
font-size: 28px;
|
||||||
color: #0d6efd;
|
color: #0d6efd;
|
||||||
@ -33,6 +38,7 @@
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.date-box {
|
.date-box {
|
||||||
background: #eef4ff;
|
background: #eef4ff;
|
||||||
color: #0d6efd;
|
color: #0d6efd;
|
||||||
@ -45,6 +51,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="p-4">
|
<body class="p-4">
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@ -104,4 +111,5 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use App\Http\Controllers\Api\ReviewController;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@ -14,6 +15,4 @@ use Illuminate\Support\Facades\Route;
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
|
Route::apiResource('reviews', ReviewController::class);
|
||||||
return $request->user();
|
|
||||||
});
|
|
||||||
|
Loading…
Reference in New Issue
Block a user