diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php index 06ef7e3..e15826b 100644 --- a/app/Http/Controllers/NotificationController.php +++ b/app/Http/Controllers/NotificationController.php @@ -9,9 +9,12 @@ class NotificationController extends Controller { public function index() { - if(auth()->user()->profile->cabang) { + if (auth()->user()->profile && auth()->user()->profile->cabang) { $notifications = auth()->user()->profile->cabang->notifications; Notification::where('to', auth()->user()->profile->cabang->id)->update(['is_read' => true]); + } else if(auth()->user()->role->name == 'admin'){ + $notifications = Notification::where('to', null)->order->get(); + Notification::where('to', null)->update(['is_read' => true]); } else { $notifications = []; } diff --git a/app/Http/Controllers/Rotasi/PengajuanController.php b/app/Http/Controllers/Rotasi/PengajuanController.php index 8e5114b..897ca8d 100644 --- a/app/Http/Controllers/Rotasi/PengajuanController.php +++ b/app/Http/Controllers/Rotasi/PengajuanController.php @@ -5,6 +5,7 @@ use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\Cabang; +use App\Models\Notification; use App\Models\Pengajuan; use Carbon\Carbon; use Illuminate\Support\Facades\DB; @@ -119,6 +120,13 @@ public function input(Request $request) ]); $pengajuanAlt->kompetensis()->createMany($kompetensi); $pengajuan["secondary_pengajuan_id"] = $pengajuanAlt->id; + Notification::create([ + 'status' => $pengajuan['status'], + 'to' => null, + 'cabang_asal_id' => $pengajuan['lokasi_awal_id'], + 'cabang_tujuan_id' => $request['lokasi_tujuan_alt_id'], + 'pengajuan_id' => $pengajuanAlt->id + ]); } else { $pengajuan["secondary_pengajuan_id"] = null; } @@ -140,6 +148,13 @@ public function input(Request $request) ]); $pengajuanAlt2->kompetensis()->createMany($kompetensi); $pengajuan["th3_pengajuan_id"] = $pengajuanAlt2->id; + Notification::create([ + 'status' => $pengajuan['status'], + 'to' => null, + 'cabang_asal_id' => $pengajuan['lokasi_awal_id'], + 'cabang_tujuan_id' => $request['lokasi_tujuan_alt2_id'], + 'pengajuan_id' => $pengajuanAlt2->id + ]); } else { $pengajuan["th3_pengajuan_id"] = null; } @@ -161,6 +176,13 @@ public function input(Request $request) 'th3_pengajuan_id' => $pengajuan['th3_pengajuan_id'] ]); $pengajuan->kompetensis()->createMany($kompetensi); + Notification::create([ + 'status' => $pengajuan['status'], + 'to' => null, + 'cabang_asal_id' => $pengajuan['lokasi_awal_id'], + 'cabang_tujuan_id' => $pengajuan['lokasi_tujuan_id'], + 'pengajuan_id' => $pengajuan->id + ]); DB::commit(); return redirect()->back()->with('success', 'Data berhasil disimpan'); diff --git a/app/Http/Controllers/Rotasi/SelektifAdminController.php b/app/Http/Controllers/Rotasi/SelektifAdminController.php index 47900a6..b167b7f 100644 --- a/app/Http/Controllers/Rotasi/SelektifAdminController.php +++ b/app/Http/Controllers/Rotasi/SelektifAdminController.php @@ -78,6 +78,14 @@ public function selektif($id, Request $request) 'cabang_tujuan_id' => $pengajuan->lokasi_tujuan_id, 'pengajuan_id' => $pengajuan->id ]); + + $notification = Notification::create([ + 'status' => $request->status, + 'to' => null, + 'cabang_asal_id' => $pengajuan->lokasi_awal_id, + 'cabang_tujuan_id' => $pengajuan->lokasi_tujuan_id, + 'pengajuan_id' => $pengajuan->id + ]); $notification->save(); if ($pengajuan->lokasi_awal_id != $pengajuan->lokasi_tujuan_id) { $notification = Notification::create([ diff --git a/app/Models/Cabang.php b/app/Models/Cabang.php index c8cec60..6a56b4a 100644 --- a/app/Models/Cabang.php +++ b/app/Models/Cabang.php @@ -34,7 +34,7 @@ class Cabang extends Model public function notifications() { - return $this->hasMany(Notification::class, 'to'); + return $this->hasMany(Notification::class, 'to')->orderBy('created_at', 'desc'); } public function notreadnotifications() diff --git a/app/Providers/NotificationProvider.php b/app/Providers/NotificationProvider.php new file mode 100644 index 0000000..0495afc --- /dev/null +++ b/app/Providers/NotificationProvider.php @@ -0,0 +1,37 @@ +composer('*', function ($view) { + if (Auth::check()) { + $user = Auth::user(); + + $hasUnreadNotifications = false; + if ($user->role->name === 'admin') { + $hasUnreadNotifications = Notification::where('to', null)->where('is_read', false)->count() > 0; + } + + $view->with('adminHasUnreadNotifications', $hasUnreadNotifications); + } + }); + } +} diff --git a/config/app.php b/config/app.php index 7667563..5e03b59 100644 --- a/config/app.php +++ b/config/app.php @@ -169,6 +169,7 @@ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, Webklex\PDFMerger\Providers\PDFMergerServiceProvider::class, + App\Providers\NotificationProvider::class, ])->toArray(), /* diff --git a/database/migrations/2024_10_30_104942_create_notifications_table.php b/database/migrations/2024_10_30_104942_create_notifications_table.php index 7a7a59f..cc7ef92 100644 --- a/database/migrations/2024_10_30_104942_create_notifications_table.php +++ b/database/migrations/2024_10_30_104942_create_notifications_table.php @@ -14,7 +14,7 @@ public function up(): void Schema::create('notifications', function (Blueprint $table) { $table->id(); $table->string("status"); - $table->foreignId("to")->constrained("cabangs")->onDelete("cascade"); + $table->foreignId("to")->nullable()->constrained("cabangs")->onDelete("cascade"); $table->boolean("is_read")->default(false); $table->foreignId("cabang_asal_id")->constrained("cabangs")->onDelete("cascade"); $table->foreignId("cabang_tujuan_id")->constrained("cabangs")->onDelete("cascade"); diff --git a/public/images/backgrounds/LOGIN.jpeg b/public/images/backgrounds/LOGIN.jpeg new file mode 100644 index 0000000..6597b6c Binary files /dev/null and b/public/images/backgrounds/LOGIN.jpeg differ diff --git a/public/images/backgrounds/LOGIN.png b/public/images/backgrounds/LOGIN.png deleted file mode 100644 index 38adc11..0000000 Binary files a/public/images/backgrounds/LOGIN.png and /dev/null differ diff --git a/public/images/slider/1.jpeg b/public/images/slider/1.jpeg new file mode 100644 index 0000000..cbf84d4 Binary files /dev/null and b/public/images/slider/1.jpeg differ diff --git a/public/images/slider/2.jpeg b/public/images/slider/2.jpeg new file mode 100644 index 0000000..fc22f7a Binary files /dev/null and b/public/images/slider/2.jpeg differ diff --git a/public/images/slider/3.jpeg b/public/images/slider/3.jpeg new file mode 100644 index 0000000..0076176 Binary files /dev/null and b/public/images/slider/3.jpeg differ diff --git a/public/images/slider/4.jpeg b/public/images/slider/4.jpeg new file mode 100644 index 0000000..fb4d711 Binary files /dev/null and b/public/images/slider/4.jpeg differ diff --git a/public/images/slider/5.jpeg b/public/images/slider/5.jpeg new file mode 100644 index 0000000..0d38589 Binary files /dev/null and b/public/images/slider/5.jpeg differ diff --git a/public/images/slider/6.jpeg b/public/images/slider/6.jpeg new file mode 100644 index 0000000..4c78a63 Binary files /dev/null and b/public/images/slider/6.jpeg differ diff --git a/public/images/slider/7.jpeg b/public/images/slider/7.jpeg new file mode 100644 index 0000000..8a27b25 Binary files /dev/null and b/public/images/slider/7.jpeg differ diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 18347f4..10f65b4 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -9,9 +9,9 @@
@include('components.modal-component')