where('checkoutable_type', 'App\Models\Asset')->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser'])->get(); $count = 0; $unacceptedAssets = $acceptances ->filter(function($acceptance) { return $acceptance->checkoutable_type == 'App\Models\Asset'; }) ->map(function($acceptance) { return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance]; }); foreach($unacceptedAssets as $unacceptedAsset) { if ($unacceptedAsset['acceptance']->assignedTo) { if (!$unacceptedAsset['acceptance']->assignedTo->locale) { Notification::locale(Setting::getSettings()->locale)->send( $unacceptedAsset['acceptance']->assignedTo, new CheckoutAssetNotification($unacceptedAsset['assetItem'], $unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['assetItem']->adminuser, $unacceptedAsset['acceptance'], '') ); } else { Notification::send( $unacceptedAsset['acceptance']->assignedTo, new CheckoutAssetNotification($unacceptedAsset['assetItem'], $unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['assetItem']->adminuser, $unacceptedAsset['acceptance'], '') ); } $count++; } } if ($unacceptedAsset['acceptance']->assignedTo->email == ''){ return "no email"; } $this->info($count.' users notified.'); } }