diff --git a/app/Helpers/Lpj.php b/app/Helpers/Lpj.php index 569f067..48db599 100644 --- a/app/Helpers/Lpj.php +++ b/app/Helpers/Lpj.php @@ -28,7 +28,7 @@ function formatTanggalIndonesia($date, $time = false) } catch (\Throwable $e) { return $date; } - + } @@ -562,3 +562,14 @@ function ubahNomorHp($nomorHp) { return "Nomor HP tidak valid"; } } + + function formatNotifikasi($data){ + $data = json_decode(json_encode($data->data)); + $data = $data->data; + $notifikasi = [ + 'title'=> 'Permohonan : '.$data->nomor_registrasi, + 'message'=> 'Status : '.str_replace(['-','_'],' ',ucwords($data->status)) + ]; + return $notifikasi; + } + diff --git a/app/Http/Controllers/PermohonanController.php b/app/Http/Controllers/PermohonanController.php index c6372f3..7da543c 100644 --- a/app/Http/Controllers/PermohonanController.php +++ b/app/Http/Controllers/PermohonanController.php @@ -22,11 +22,13 @@ use Modules\Lpj\Models\NilaiPlafond; use Modules\Lpj\Models\Permohonan; use Modules\Lpj\Models\StatusPermohonan; use Modules\Lpj\Models\TujuanPenilaian; +use Modules\Lpj\Notifications\PermohonanNotif; use Modules\Lpj\Services\PermohonanHistoryService; use Illuminate\Support\Facades\Auth; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\DB; use Modules\Lpj\Models\Penilaian; +use Modules\Usermanagement\Models\User; class PermohonanController extends Controller { @@ -63,6 +65,10 @@ class PermohonanController extends Controller // Save to database $permohonan = Permohonan::create($validate); + $user_ = User::find($permohonan->created_by); + $user_->notify(new PermohonanNotif($permohonan)); + + // Create history $this->historyService->createHistory( $permohonan, diff --git a/app/Models/Base.php b/app/Models/Base.php index eb7b4d8..63f172b 100644 --- a/app/Models/Base.php +++ b/app/Models/Base.php @@ -7,6 +7,7 @@ use Spatie\Activitylog\LogOptions; use Spatie\Activitylog\Traits\LogsActivity; use Wildside\Userstamps\Userstamps; + use Illuminate\Notifications\Notifiable; /** @@ -14,7 +15,7 @@ */ class Base extends Model { - use LogsActivity, SoftDeletes, Userstamps; + use LogsActivity, SoftDeletes, Userstamps, Notifiable; protected $connection; diff --git a/app/Notifications/PermohonanNotif.php b/app/Notifications/PermohonanNotif.php new file mode 100644 index 0000000..3902cfd --- /dev/null +++ b/app/Notifications/PermohonanNotif.php @@ -0,0 +1,50 @@ +permohonan = $permohonan; + } + + /** + * Get the notification's delivery channels. + */ + public function via($notifiable): array + { + return ['mail','database']; + } + + /** + * Get the mail representation of the notification. + */ + public function toMail($notifiable): MailMessage + { + return (new MailMessage) + ->line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + */ + public function toArray($notifiable): array + { + return [ + 'data' => $this->permohonan, + ]; + } +}