than create notification $documentIds = ModelsDocumentReminder::whereDate('date', $now)->pluck('document_id'); $documents = Document::whereIn('id', $documentIds)->whereIn('status', [Document::ACTIVE, Document::UPDATE])->get(); foreach ($documents as $doc) { // only set expired when enddate is set if ($doc->end_date->format('d-m-Y') >= $now->format('d-m-Y')) { $doc->update(['status' => Document::EXPIRED]); } // create notification Notification::create([ 'content' => $doc->type->name.' - '.$doc->name. ' akan berakhir pada '. $doc->end_date->format('d-m-Y'), 'date' => $now, 'model_related' => Document::class, 'model_id' => $doc->id, 'status' => Notification::STATUS_UNREAD ]); } return array_merge(parent::share($request), [ 'auth' => [ 'user' => $request->user(), ], 'ziggy' => function () use ($request) { return array_merge((new Ziggy)->toArray(), [ 'location' => $request->url(), ]); }, 'flash' => [ 'message' => fn () => $request->session()->get('message') ], 'notify' => [ 'notifications' => Notification::orderBy('created_at', 'desc')->get(), 'notification_has_unread' => Notification::where('status', Notification::STATUS_UNREAD)->count() ] ]); } }