private function passData($id = null) { $HQAddresses = new \App\Models\Addresses(); $HQPhones = new \App\Models\Phones(); $company = new \App\Models\Companies(); $ultimateParentCompany = new \App\Models\Companies(); if (!is_null($id)) { $company = Companies::findOrNew($id); $mediaContacts = $company->mediaContacts()->get(); $attachments = $company->attachments()->get(); $ultimateParentCompany = $company->ultimateParent()->get(); } else { if (!Session::has('MediaContacts')) { Session::set('MediaContacts', $company->mediaContacts()->get()); } if (!Session::has('CompanyAttachments')) { Session::set('CompanyAttachments', $company->attachments()->get()); } $mediaContacts = Session::get('MediaContacts'); $attachments = Session::get("CompanyAttachments"); } $eSize = EmployeeSize::all()->toArray(); $gProfile = GrowthProfile::where('id_Growth_Profile', '>', 1)->get()->toArray(); $oship = Ownership::all()->toArray(); $rStage = RevenueStage::where('id_Revenue_Stage', '>', 1)->get()->toArray(); $cType = CompanyType::all()->toArray(); $csType = CompanySubType::all()->toArray(); $uParent = Companies::where("Deleted", "=", NULL)->get()->sortBy('Company_Full_Name')->toArray(); $products = $company->products()->whereNull("Deleted"); foreach ($products->get() as $product) { $productFocusTypeList[$product->id_Product] = []; $productTypeList = []; foreach ($product->focusSubType()->get() as $productSubType) { $productTypeList[0] = $productSubType->Product_Focus_Sub_Type; $productTypeListValues = ProductFocusType::where('id_Product_Focus_Type', '=', $productSubType->id_Product_Focus_Type)->get()->first(); $productTypeList[1] = $productTypeListValues->Product_Focus_Type; $productFocusTypeList[$product->id_Product][] = $productTypeList; } } if ($company->headquaters()->get()->count()) { $HQAddresses = Addresses::findOrNew($company->headquaters()->get()->first()->AddressId); } if ($company->headquaters()->get()->count() && $company->headquaters()->get()->first()->PhoneId) { $HQPhones = Phones::findOrNew($company->headquaters()->get()->first()->PhoneId); } foreach ($eSize as $emSize) { $employeeSize[$emSize["id_Employee_Size"]] = $emSize["Employee_Size"]; } foreach ($gProfile as $gwProfile) { $growthProfile[$gwProfile["id_Growth_Profile"]] = $gwProfile["Growth_Profile"]; } foreach ($oship as $owship) { $ownership[$owship["id_Ownership"]] = $owship["Ownership"]; } foreach ($rStage as $revStage) { $revenueStage[$revStage["id_Revenue_Stage"]] = $revStage["Revenue_Stage"]; } foreach ($cType as $coType) { $companyType[$coType["id_Company_Type"]] = $coType["Company_Type"]; } foreach ($csType as $coSuType) { $companySubType[$coSuType["id_Company_Sub_Type"]] = $coSuType["Company_Sub_Type_Name"]; } foreach ($uParent as $ulParent) { $ultimateParent[$ulParent["id_Company"]] = $ulParent["Company_Full_Name"]; } $country = Country::getListCountries(); return compact("employeeSize", "growthProfile", "productFocusTypeList", "ownership", "revenueStage", "companyType", "companySubType", "company", "ultimateParent", "mediaContacts", "country", "HQAddresses", "HQPhones", "products", "attachments", "ultimateParentCompany"); }
public function saveObjectRelation(Request $request, $newsModel) { DB::table('News_Company')->where("id_News", "=", $newsModel->id_News)->delete(); DB::table('News_Product')->where("id_News", "=", $newsModel->id_News)->delete(); DB::table('News_Employee')->where("id_News", "=", $newsModel->id_News)->delete(); foreach ($newsModel->target as $relationTarget) { $matches = preg_grep('/^' . $relationTarget . "_*/i", array_keys($request->all())); foreach ($matches as $targetItem) { if ($request->get($targetItem) == "on") { $ObjectTrgetId = str_replace($relationTarget . "_", "", $targetItem); switch ($relationTarget) { case 'Companies': $newsModel->company()->save(Companies::findOrNew($ObjectTrgetId)); break; case 'People': $employeeModel = Employee::where("id_People", "=", $ObjectTrgetId)->first(); //dd($employeeModel); $newsModel->employee()->save(Employee::findOrNew($employeeModel->id_Employee)); break; case 'Vertical': break; case 'Products': $newsModel->product()->save(Products::findOrNew($ObjectTrgetId)); break; case 'Events': break; } } } } }