public function run() { DB::table('form_settings')->delete(); $alwaysCopy = ['*****@*****.**', '*****@*****.**']; $perLocationCopy = ['Brookhaven' => ['BuildingQuote:Rigid Frame' => ['*****@*****.**'], 'BuildingQuote:Galv-Econ' => ['*****@*****.**'], 'BuildingQuote:Pole Barn' => ['*****@*****.**'], 'BuildingQuote:Roof' => [], 'ContactForm' => [], 'EmploymentApp' => [], 'CreditApp' => []], 'Tupelo' => ['BuildingQuote:Rigid Frame' => ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'], 'BuildingQuote:Galv-Econ' => ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'], 'BuildingQuote:Pole Barn' => ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'], 'BuildingQuote:Roof' => ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'], 'ContactForm' => [], 'EmploymentApp' => [], 'CreditApp' => []], 'Lake Charles' => ['BuildingQuote:Rigid Frame' => ['*****@*****.**', '*****@*****.**'], 'BuildingQuote:Galv-Econ' => ['*****@*****.**', '*****@*****.**'], 'BuildingQuote:Pole Barn' => ['*****@*****.**', '*****@*****.**'], 'BuildingQuote:Roof' => [], 'ContactForm' => [], 'EmploymentApp' => [], 'CreditApp' => []], 'Benton' => ['BuildingQuote:Rigid Frame' => ['*****@*****.**', '*****@*****.**'], 'BuildingQuote:Galv-Econ' => ['*****@*****.**', '*****@*****.**'], 'BuildingQuote:Pole Barn' => ['*****@*****.**', '*****@*****.**'], 'BuildingQuote:Roof' => [], 'ContactForm' => [], 'EmploymentApp' => [], 'CreditApp' => []], 'Jackson' => ['BuildingQuote:Rigid Frame' => ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'], 'BuildingQuote:Galv-Econ' => ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'], 'BuildingQuote:Pole Barn' => ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'], 'BuildingQuote:Roof' => ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'], 'ContactForm' => [], 'EmploymentApp' => [], 'CreditApp' => []]]; $locations = Location::all(); $rigidFrameRole = Role::where('name', 'RigidFrameSales')->first(); $galvEconRole = Role::where('name', 'GalvEconSales')->first(); $poleBarnRole = Role::where('name', 'PoleBarnSales')->first(); $roofingRole = Role::where('name', 'RoofingSales')->first(); $contactRole = Role::where('name', 'GeneralManager')->first(); $employeeRole = Role::where('name', 'HR')->first(); foreach ($locations as $location) { $rigidFrameBuildingQuoteSettings = new FormSettings(); $rigidFrameBuildingQuoteSettings->model = 'App\\Models\\Forms\\BuildingQuote:Rigid Frame'; $rigidFrameBuildingQuoteSettings->rotation()->associate($rigidFrameRole); $location->formSettings()->save($rigidFrameBuildingQuoteSettings); $galvEconBuildingQuoteSettings = new FormSettings(); $galvEconBuildingQuoteSettings->model = 'App\\Models\\Forms\\BuildingQuote:Galv-Econ'; $galvEconBuildingQuoteSettings->rotation()->associate($galvEconRole); $location->formSettings()->save($galvEconBuildingQuoteSettings); $poleBarnBuildingQuoteSettings = new FormSettings(); $poleBarnBuildingQuoteSettings->model = 'App\\Models\\Forms\\BuildingQuote:Pole Barn'; $poleBarnBuildingQuoteSettings->rotation()->associate($poleBarnRole); $location->formSettings()->save($poleBarnBuildingQuoteSettings); $roofBuildingQuoteSettings = new FormSettings(); $roofBuildingQuoteSettings->model = 'App\\Models\\Forms\\BuildingQuote:Roof'; $roofBuildingQuoteSettings->rotation()->associate($roofingRole); $location->formSettings()->save($roofBuildingQuoteSettings); $contactFormSettings = new FormSettings(); $contactFormSettings->model = 'App\\Models\\Forms\\ContactForm'; $contactFormSettings->rotation()->associate($contactRole); $location->formSettings()->save($contactFormSettings); $employmentAppSettings = new FormSettings(); $employmentAppSettings->model = 'App\\Models\\Forms\\EmploymentApp'; $employmentAppSettings->rotation()->associate($employeeRole); $location->formSettings()->save($employmentAppSettings); $creditAppSettings = new FormSettings(); $creditAppSettings->model = 'App\\Models\\Forms\\CreditApp'; $creditAppSettings->rotation()->associate($contactRole); $location->formSettings()->save($creditAppSettings); $rigidFrameBuildingQuoteSettings->save(); $galvEconBuildingQuoteSettings->save(); $poleBarnBuildingQuoteSettings->save(); $roofBuildingQuoteSettings->save(); $contactFormSettings->save(); $employmentAppSettings->save(); $creditAppSettings->save(); $settingsArr = [$rigidFrameBuildingQuoteSettings, $galvEconBuildingQuoteSettings, $poleBarnBuildingQuoteSettings, $roofBuildingQuoteSettings, $contactFormSettings, $employmentAppSettings, $creditAppSettings]; if ($location->parent) { $location = $location->parent; } foreach ($perLocationCopy[$location->name] as $key => $value) { foreach ($value as $recipient) { $formRecipient = new FormRecipient(); if ($person = Person::where('email', $recipient)->first()) { $employee = Employee::whereIs($person); if ($employee != null) { $formRecipient->employee()->associate(Employee::whereIs($person)); } } else { $formRecipient->email = $recipient; } $formRecipient->save(); foreach ($settingsArr as $settings) { if (strpos($settings->model, $key) !== false) { $settings->copyTo()->save($formRecipient); break; } } } } foreach ($alwaysCopy as $recipient) { $formRecipient = new FormRecipient(); if ($person = Person::where('email', $recipient)->first()) { $employee = Employee::whereIs($person); if ($employee != null) { $formRecipient->employee()->associate(Employee::whereIs($person)); } } else { $formRecipient->email = $recipient; } $formRecipient->save(); foreach ($settingsArr as $settings) { $settings->copyTo()->save($formRecipient); } } } }
public function search() { $query = Request::get('query'); // Find employees and emails that match -- return both $people = Person::where('full_name', 'like', "%{$query}%")->limit(6)->get(); $employees = []; foreach ($people as $person) { array_push($employees, Employee::whereIs($person)); } $formRecipients = FormRecipient::where('email', 'like', "%{$query}%")->limit(6)->get(); $return = []; foreach ($employees as $employee) { array_push($return, ['value' => $employee->full_name]); } foreach ($formRecipients as $formRecipient) { array_push($return, ['value' => $formRecipient->email]); } return array_unique($return, SORT_REGULAR); }