diff --git a/[address], b/[address], new file mode 100644 index 0000000..e69de29 diff --git a/[image], b/[image], new file mode 100644 index 0000000..e69de29 diff --git a/[location], b/[location], new file mode 100644 index 0000000..e69de29 diff --git a/[name], b/[name], new file mode 100644 index 0000000..e69de29 diff --git a/[price], b/[price], new file mode 100644 index 0000000..e69de29 diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 19da401..44800fd 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -27,7 +27,7 @@ class LoginController extends Controller * * @var string */ - protected $redirectTo = '/venue/capitano'; + protected $redirectTo = '/home'; /** * Create a new controller instance. @@ -47,6 +47,17 @@ public function logout(Request $request) $request->session()->invalidate(); $request->session()->regenerateToken(); - return redirect('/venue/das'); + session()->flash('error', 'Berhasil logout!'); + return redirect('/home'); } + + protected function authenticated(Request $request, $user) + { + session()->flash('success', 'Login berhasil!'); + if ($user->role === 'admin') { + return redirect('/admin'); + } + return redirect()->intended($this->redirectTo); + } + } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index ab7ef63..961ea36 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -28,7 +28,7 @@ class RegisterController extends Controller * * @var string */ - protected $redirectTo = '/'; + protected $redirectTo = '/home'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/admin/AdminController.php b/app/Http/Controllers/admin/AdminController.php new file mode 100644 index 0000000..8afae9a --- /dev/null +++ b/app/Http/Controllers/admin/AdminController.php @@ -0,0 +1,45 @@ +user()->venue_id); + + $todayBookings = Booking::whereDate('created_at', now()) + ->whereHas('table', function ($query) use ($venue) { + $query->where('venue_id', $venue->id); + }) + ->count(); + + $totalTables = Table::where('venue_id', $venue->id)->count(); + $usedTables = Table::where('venue_id', $venue->id)->where('status', 'booked')->count(); + $availableTables = Table::where('venue_id', $venue->id)->where('status', 'available')->count(); + + $recentBookings = Booking::whereHas('table', function ($query) use ($venue) { + $query->where('venue_id', $venue->id); + }) + ->latest() + ->take(5) + ->with(['user', 'table']) + ->get(); + + return view('admin.dashboard', compact( + 'venue', + 'todayBookings', + 'totalTables', + 'usedTables', + 'availableTables', + 'recentBookings' + )); + } +} diff --git a/app/Http/Controllers/admin/BookingsController.php b/app/Http/Controllers/admin/BookingsController.php new file mode 100644 index 0000000..a45a683 --- /dev/null +++ b/app/Http/Controllers/admin/BookingsController.php @@ -0,0 +1,20 @@ +orderBy('start_time', 'desc') + ->paginate(10); + + return view('admin.bookings.index', compact('bookings')); + } + +} diff --git a/app/Http/Controllers/admin/TableController.php b/app/Http/Controllers/admin/TableController.php new file mode 100644 index 0000000..11b934c --- /dev/null +++ b/app/Http/Controllers/admin/TableController.php @@ -0,0 +1,36 @@ +user()->venue_id)->paginate(10); + return view('admin.tables.index', compact('tables')); + } + + public function editTable($id) + { + $table = Table::findOrFail($id); + return view('admin.tables.edit', compact('table')); + } + + public function updateTable(Request $request, $id) + { + $table = Table::findOrFail($id); + + $table->update([ + 'name' => $request->name, + 'brand' => $request->brand, + 'status' => $request->status, + ]); + + return redirect()->route('admin.tables.index')->with('success', 'Data meja berhasil diperbarui.'); + } + +} diff --git a/app/Http/Controllers/pages/BookingController.php b/app/Http/Controllers/pages/BookingController.php new file mode 100644 index 0000000..7d22fea --- /dev/null +++ b/app/Http/Controllers/pages/BookingController.php @@ -0,0 +1,48 @@ +validate([ + 'table_id' => 'required|exists:tables,id', + 'start_time' => 'required|date', + 'end_time' => 'required|date|after:start_time', + ]); + + // Cek apakah meja sedang dibooking pada waktu tersebut + $conflict = Booking::where('table_id', $request->table_id) + ->where(function($query) use ($request) { + $query->whereBetween('start_time', [$request->start_time, $request->end_time]) + ->orWhereBetween('end_time', [$request->start_time, $request->end_time]) + ->orWhere(function($query) use ($request) { + $query->where('start_time', '<', $request->start_time) + ->where('end_time', '>', $request->end_time); + }); + }) + ->where('status', '!=', 'cancelled') // skip booking yang dibatalkan + ->exists(); + + if ($conflict) { + return response()->json(['message' => 'Meja sudah dibooking di jam tersebut'], 409); + } + + Booking::create([ + 'table_id' => $request->table_id, + 'user_id' => Auth::id(), + 'start_time' => $request->start_time, + 'end_time' => $request->end_time, + 'status' => 'booked', + ]); + + return response()->json(['message' => 'Booking berhasil']); + } +} diff --git a/app/Http/Controllers/pages/HomeController.php b/app/Http/Controllers/pages/HomeController.php index 424fbd2..38aa327 100644 --- a/app/Http/Controllers/pages/HomeController.php +++ b/app/Http/Controllers/pages/HomeController.php @@ -7,10 +7,10 @@ class HomeController extends Controller { - public function __construct() - { - $this->middleware('auth'); - } + // public function __construct() + // { + // $this->middleware('auth'); + // } public function index() { return view('pages.home'); diff --git a/app/Http/Controllers/pages/VenueController.php b/app/Http/Controllers/pages/VenueController.php index 2279773..2a61a53 100644 --- a/app/Http/Controllers/pages/VenueController.php +++ b/app/Http/Controllers/pages/VenueController.php @@ -3,67 +3,27 @@ namespace App\Http\Controllers\pages; use App\Http\Controllers\Controller; +use App\Models\Venue; // Pastikan model Venue di-import use Illuminate\Http\Request; class VenueController extends Controller { public function venue($venueName) { - $venues = [ - 'capitano' => [ - 'name' => 'Capitano Billiard', - 'location' => 'Genteng', - 'address' => 'Jl. Hasanudin No.II, Dusun Krajan, Genteng Wetan, Kec. Genteng, Kabupaten Banyuwangi', - 'price' => 30000, - 'image' => 'images/billiard2.jpg', - 'tables' => [ - ['name' => 'Table 1', 'brand' => 'Cosmic', 'status' => 'Available'], - ['name' => 'Table 2', 'brand' => 'Cosmic', 'status' => 'Booked'], - ['name' => 'Table 3', 'brand' => 'Cosmic', 'status' => 'Available'], - ['name' => 'Table 4', 'brand' => 'Cosmic', 'status' => 'Available'], - ['name' => 'Table 5', 'brand' => 'A Plus Premier', 'status' => 'Booked'], - ['name' => 'Table 6', 'brand' => 'A Plus Premier', 'status' => 'Booked'], - ['name' => 'Table 7', 'brand' => 'A Plus Premier', 'status' => 'Available'], - ], - ], - 'osing' => [ - 'name' => 'Osing Billiard Center', - 'location' => 'Lidah', - 'address' => 'Dusun Krajan, Kalirejo, Kec. Kabat, Kabupaten Banyuwangi', - 'price' => 25000, - 'image' => 'images/billiard3.jpg', - 'tables' => [ - ['name' => 'Table 1', 'brand' => 'Xingjue', 'status' => 'Booked'], - ['name' => 'Table 2', 'brand' => 'Xingjue', 'status' => 'Booked'], - ['name' => 'Table 3', 'brand' => 'Xingjue', 'status' => 'Available'], - ['name' => 'Table 4', 'brand' => 'Xingjue', 'status' => 'Available'], - ['name' => 'Table 5', 'brand' => 'Xingjue', 'status' => 'Booked'], - ['name' => 'Table 6', 'brand' => 'Xingjue', 'status' => 'Available'], - ['name' => 'Table 7', 'brand' => 'Xingjue', 'status' => 'Available'], - ], - ], - 'das' => [ - 'name' => 'DAS Game & Billiard', - 'location' => 'Jalen', - 'address' => 'Jl. Samiran, Jalen Parungan, Setail, Kec. Genteng, Kabupaten Banyuwangi', - 'price' => 20000, - 'image' => 'images/billiard4.jpg', - 'tables' => [ - ['name' => 'Table 1', 'brand' => 'Cosmic', 'status' => 'Available'], - ['name' => 'Table 2', 'brand' => 'Cosmic', 'status' => 'Booked'], - ['name' => 'Table 3', 'brand' => 'Cosmic', 'status' => 'Available'], - ['name' => 'Table 4', 'brand' => 'Cosmic', 'status' => 'Booked'], - ['name' => 'Table 5', 'brand' => 'Cosmic', 'status' => 'Booked'], - ['name' => 'Table 6', 'brand' => 'Cosmic', 'status' => 'Available'], - ['name' => 'Table 7', 'brand' => 'Cosmic', 'status' => 'Available'], - ['name' => 'Table 8', 'brand' => 'Cosmic', 'status' => 'Booked'], - ], - ], - ]; - - if (!isset($venues[$venueName])) { + // Mengambil venue berdasarkan nama yang diberikan + $venue = Venue::where('name', 'like', '%' . ucfirst($venueName) . '%')->first(); + + // Jika venue tidak ditemukan, tampilkan error 404 + if (!$venue) { abort(404); } - - return view('pages.venue', ['venue' => $venues[$venueName]]); + + // Ambil tabel-tabel terkait dengan venue + $tables = $venue->tables; + + // Mengirim data venue dan tabel ke view + return view('pages.venue', [ + 'venue' => $venue, + 'tables' => $tables + ]); } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 494c050..08e5e8c 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -64,5 +64,6 @@ class Kernel extends HttpKernel 'signed' => \App\Http\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + 'is_admin' => \App\Http\Middleware\IsAdmin::class, ]; } diff --git a/app/Http/Middleware/IsAdmin.php b/app/Http/Middleware/IsAdmin.php new file mode 100644 index 0000000..04deab6 --- /dev/null +++ b/app/Http/Middleware/IsAdmin.php @@ -0,0 +1,23 @@ +check() && auth()->user()->role === 'admin') { + return $next($request); + } + + abort(403); // atau redirect('/login') +} +} diff --git a/app/Models/Booking.php b/app/Models/Booking.php new file mode 100644 index 0000000..40fea22 --- /dev/null +++ b/app/Models/Booking.php @@ -0,0 +1,23 @@ +belongsTo(Table::class); + } + + public function user() + { + return $this->belongsTo(User::class); + } +} diff --git a/app/Models/Table.php b/app/Models/Table.php new file mode 100644 index 0000000..c0a51a2 --- /dev/null +++ b/app/Models/Table.php @@ -0,0 +1,23 @@ +belongsTo(Venue::class); + } + + public function bookings() + { + return $this->hasMany(Booking::class); + } +} diff --git a/app/Models/Venue.php b/app/Models/Venue.php new file mode 100644 index 0000000..22cf6b9 --- /dev/null +++ b/app/Models/Venue.php @@ -0,0 +1,18 @@ +hasMany(Table::class); + } +} diff --git a/database/migrations/2025_04_28_044407_create_venues_table.php b/database/migrations/2025_04_28_044407_create_venues_table.php new file mode 100644 index 0000000..6e582f8 --- /dev/null +++ b/database/migrations/2025_04_28_044407_create_venues_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('name'); // Nama venue + $table->string('location'); // Lokasi venue (misalnya: Jakarta) + $table->string('address'); // Alamat venue + $table->integer('price'); + $table->string('image')->nullable(); // Gambar venue (opsional) + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('venues'); + } +}; diff --git a/database/migrations/2025_04_28_044839_create_tables_table.php b/database/migrations/2025_04_28_044839_create_tables_table.php new file mode 100644 index 0000000..0fc4596 --- /dev/null +++ b/database/migrations/2025_04_28_044839_create_tables_table.php @@ -0,0 +1,31 @@ +id(); + $table->foreignId('venue_id')->constrained(); // Referensi ke tabel venues + $table->string('name'); + $table->string('brand'); + $table->enum('status', ['Available', 'Booked'])->default('Available'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('tables'); + } +}; diff --git a/database/migrations/2025_04_28_045045_create_bookings_table.php b/database/migrations/2025_04_28_045045_create_bookings_table.php new file mode 100644 index 0000000..fb113e1 --- /dev/null +++ b/database/migrations/2025_04_28_045045_create_bookings_table.php @@ -0,0 +1,32 @@ +id(); + $table->foreignId('table_id')->constrained(); // Referensi ke tabel tables + $table->foreignId('user_id')->constrained(); // Referensi ke tabel users + $table->dateTime('start_time'); + $table->dateTime('end_time'); + $table->enum('status', ['Booked', 'Cancelled', 'Completed'])->default('Booked'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('bookings'); + } +}; diff --git a/database/migrations/2025_05_02_073103_add_role_to_users_table.php b/database/migrations/2025_05_02_073103_add_role_to_users_table.php new file mode 100644 index 0000000..ef5ee4f --- /dev/null +++ b/database/migrations/2025_05_02_073103_add_role_to_users_table.php @@ -0,0 +1,31 @@ +unsignedBigInteger('venue_id')->nullable()->after('role'); + $table->foreign('venue_id')->references('id')->on('venues')->onDelete('set null'); + }); +} + +public function down(): void +{ + Schema::table('users', function (Blueprint $table) { + // Menghapus foreign key dan kolom venue_id + if (Schema::hasColumn('users', 'venue_id')) { + $table->dropForeign(['venue_id']); // Menghapus foreign key constraint + $table->dropColumn('venue_id'); // Menghapus kolom venue_id + } + }); +} +}; diff --git a/database/seeders/VenueSeeder.php b/database/seeders/VenueSeeder.php new file mode 100644 index 0000000..0b818ea --- /dev/null +++ b/database/seeders/VenueSeeder.php @@ -0,0 +1,81 @@ + [ + 'name' => 'Capitano Billiard', + 'location' => 'Genteng', + 'address' => 'Jl. Hasanudin No.II, Dusun Krajan, Genteng Wetan, Kec. Genteng, Kabupaten Banyuwangi', + 'price' => 30000, + 'image' => 'images/billiard2.jpg', + 'tables' => [ + ['name' => 'Table 1', 'brand' => 'Cosmic', 'status' => 'Available'], + ['name' => 'Table 2', 'brand' => 'Cosmic', 'status' => 'Booked'], + ['name' => 'Table 3', 'brand' => 'Cosmic', 'status' => 'Available'], + ['name' => 'Table 4', 'brand' => 'Cosmic', 'status' => 'Available'], + ['name' => 'Table 5', 'brand' => 'A Plus Premier', 'status' => 'Booked'], + ['name' => 'Table 6', 'brand' => 'A Plus Premier', 'status' => 'Booked'], + ], + ], + 'osing' => [ + 'name' => 'Osing Billiard Center', + 'location' => 'Lidah', + 'address' => 'Dusun Krajan, Kalirejo, Kec. Kabat, Kabupaten Banyuwangi', + 'price' => 25000, + 'image' => 'images/billiard3.jpg', + 'tables' => [ + ['name' => 'Table 1', 'brand' => 'Xingjue', 'status' => 'Booked'], + ['name' => 'Table 2', 'brand' => 'Xingjue', 'status' => 'Booked'], + ['name' => 'Table 3', 'brand' => 'Xingjue', 'status' => 'Available'], + ['name' => 'Table 4', 'brand' => 'Xingjue', 'status' => 'Available'], + ['name' => 'Table 5', 'brand' => 'Xingjue', 'status' => 'Booked'], + ['name' => 'Table 6', 'brand' => 'Xingjue', 'status' => 'Available'], + ['name' => 'Table 7', 'brand' => 'Xingjue', 'status' => 'Available'], + ], + ], + 'das' => [ + 'name' => 'DAS Game & Billiard', + 'location' => 'Jalen', + 'address' => 'Jl. Samiran, Jalen Parungan, Setail, Kec. Genteng, Kabupaten Banyuwangi', + 'price' => 20000, + 'image' => 'images/billiard4.jpg', + 'tables' => [ + ['name' => 'Table 1', 'brand' => 'Cosmic', 'status' => 'Available'], + ['name' => 'Table 2', 'brand' => 'Cosmic', 'status' => 'Booked'], + ['name' => 'Table 3', 'brand' => 'Cosmic', 'status' => 'Available'], + ['name' => 'Table 4', 'brand' => 'Cosmic', 'status' => 'Booked'], + ['name' => 'Table 5', 'brand' => 'Cosmic', 'status' => 'Booked'], + ['name' => 'Table 6', 'brand' => 'Cosmic', 'status' => 'Available'], + ['name' => 'Table 7', 'brand' => 'Cosmic', 'status' => 'Available'], + ['name' => 'Table 8', 'brand' => 'Cosmic', 'status' => 'Booked'], + ], + ], + ]; + + foreach ($venues as $venueData) { + // Membuat venue baru + $venue = Venue::create([ + 'name' => $venueData['name'], + 'location' => $venueData['location'], + 'address' => $venueData['address'], + 'price' => $venueData['price'], + 'image' => $venueData['image'], + ]); + + // Menambahkan tabel untuk setiap venue + foreach ($venueData['tables'] as $tableData) { + $venue->tables()->create($tableData); // Menambahkan meja ke venue + } + } + } +} diff --git a/resources/views/admin/bookings/index.blade.php b/resources/views/admin/bookings/index.blade.php new file mode 100644 index 0000000..c2bc259 --- /dev/null +++ b/resources/views/admin/bookings/index.blade.php @@ -0,0 +1,42 @@ +@extends('layouts.admin') + +@section('content') +
User | +Meja | +Mulai | +Selesai | +Status | +|
---|---|---|---|---|---|
{{ $booking->user->name }} | +{{ $booking->table->name }} | +{{ \Carbon\Carbon::parse($booking->start_time)->format('H:i d/m') }} | +{{ \Carbon\Carbon::parse($booking->end_time)->format('H:i d/m') }} | ++ + {{ ucfirst($booking->status) }} + + | +|
Belum ada data booking. | +
Selamat datang, {{ auth()->user()->name }}!
+ +Jumlah Booking Hari Ini
+{{ $todayBookings }}
+ + +Total Meja
+{{ $totalTables }}
+ + +Meja Sedang Digunakan
+{{ $usedTables }}
+ + +Meja Tersedia
+{{ $availableTables }}
+ +Belum ada booking terbaru.
+ @else +Nama User | +Meja | +Waktu | +Status | +
---|---|---|---|
{{ $booking->user->name }} | +{{ $booking->table->name }} | +{{ \Carbon\Carbon::parse($booking->start_time)->format('H:i') }} - + {{ \Carbon\Carbon::parse($booking->end_time)->format('H:i') }} | +{{ $booking->status }} | +
Nama Meja | +Merek | +Status | +Aksi | +
---|---|---|---|
{{ $table->name }} | +{{ $table->brand }} | ++ + {{ $table->status }} + + | ++ Edit + | +
Belum ada data meja. | +
Halo, {{ Auth::user()->name }}
- @else -Kamu belum login
+ @if (session('success') || session('error')) +