%PDF- %PDF-
Direktori : /home/silvzytp/calling_code/app/Http/Middleware/ |
Current File : //home/silvzytp/calling_code/app/Http/Middleware/ReminderMiddleware.php |
<?php namespace App\Http\Middleware; use Closure; use Carbon\Carbon; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Notifications\ReminderNotification; use App\Models\Colling; class ReminderMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse */ public function handle(Request $request, Closure $next) { $call_data = DB::table('collings')->select('id','name','serial','updated_at','reminder_date','agent_id') ->whereNotNull('reminder_date') ->whereNull('reminder_set') ->where('status',1) ->whereDate('reminder_date','<',Carbon::now()->format('Y-m-d')) ->get(); foreach ($call_data as $notification) { Colling::find($notification->id)->update(['reminder_set'=>1]); $notification = collect($notification); $agent = User::find($notification['agent_id']); $notification['agent_name'] = $agent->name; $agent->notify(new ReminderNotification($notification)); } return $next($request); } }