public function index() { if (!$this->hasPermission($this->menuPermissionName)) { return view($this->viewPermissiondeniedName); } $provinces = Province::whereHas('branchs', function ($q) { $q->where('isheadquarter', true); })->orderBy('name', 'asc')->get(['id', 'name']); $provinceselectlist = array(); array_push($provinceselectlist, ':เลือกจังหวัด'); foreach ($provinces as $item) { array_push($provinceselectlist, $item->id . ':' . $item->name); } $occupations = Occupation::orderBy('name', 'asc')->get(['id', 'name']); $occupationselectlist = array(); array_push($occupationselectlist, ':เลือกอาชีพ'); foreach ($occupations as $item) { array_push($occupationselectlist, $item->id . ':' . $item->name); } $addprovinces = Province::orderBy('name', 'asc')->get(['id', 'name']); $addprovinceselectlist = array(); array_push($addprovinceselectlist, ':เลือกจังหวัด'); foreach ($addprovinces as $item) { array_push($addprovinceselectlist, $item->id . ':' . $item->name); } $amphurs = Amphur::has('customers')->orderBy('name', 'asc')->get(['id', 'name']); $amphurselectlist = array(); array_push($amphurselectlist, ':เลือกเขต/อำเภอ'); foreach ($amphurs as $item) { array_push($amphurselectlist, $item->id . ':' . $item->name); } $districts = District::has('customers')->orderBy('name', 'asc')->get(['id', 'name']); $districtselectlist = array(); array_push($districtselectlist, ':เลือกตำบล/แขวง'); foreach ($districts as $item) { array_push($districtselectlist, $item->id . ':' . $item->name); } if (Auth::user()->isadmin) { $employees = Employee::orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'firstname', 'lastname']); } else { $provinceid = Auth::user()->provinceid; $employees = Employee::whereHas('branch', function ($q) use($provinceid) { $q->where('provinceid', $provinceid); })->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'firstname', 'lastname']); } $employeeselectlist = array(); array_push($employeeselectlist, ':เลือกพนักงาน'); foreach ($employees as $emp) { array_push($employeeselectlist, $emp->id . ':' . $emp->firstname . ' ' . $emp->lastname); } $carmodels = CarModel::whereHas("carbrand", function ($q) { $q->where('ismain', true); })->orderBy('name', 'asc')->get(['id', 'name']); $carmodelselectlist = array(); array_push($carmodelselectlist, ':เลือกแบบ'); foreach ($carmodels as $cm) { array_push($carmodelselectlist, $cm->id . ':' . $cm->name); } $colors = Color::all(['id', 'code', 'name']); $colorselectlist = array(); array_push($colorselectlist, ':เลือกสี'); foreach ($colors as $item) { array_push($colorselectlist, $item->id . ':' . $item->code . ' - ' . $item->name); } $defaultProvince = ''; if (Auth::user()->isadmin == false) { $defaultProvince = Auth::user()->provinceid; } return view($this->viewname, ['colorselectlist' => implode(";", $colorselectlist), 'provinceselectlist' => implode(";", $provinceselectlist), 'addprovinceselectlist' => implode(";", $addprovinceselectlist), 'amphurselectlist' => implode(";", $amphurselectlist), 'districtselectlist' => implode(";", $districtselectlist), 'carmodelselectlist' => implode(";", $carmodelselectlist), 'employeeselectlist' => implode(";", $employeeselectlist), 'occupationselectlist' => implode(";", $occupationselectlist), 'defaultProvince' => $defaultProvince]); }