/** * Create new review for a company. * * @param Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response */ public function create(Requests\CreateReviewRequest $request) { try { $company = Company::findOrFail($request->input('company-id')); $review = new Review($request->except('company-id')); $company->reviews()->save($review); return redirect()->back()->with(['message' => 'Отзыв будет опубликован после модерации.']); } catch (\Exception $e) { return response()->view('errors.' . '503'); } }
public function cart($id) { try { $company = Company::findOrFail($id); $reviews = $company->reviews()->get(); $phones = $company->contacts->phones()->filled()->get(); $groups = $company->contacts->groups; $logo_url = empty($company->logo_url) && File::exists("uploads/images/" . $company->logo_url) ? "backend/themes/default/images/no_logo.svg" : "uploads/images/" . $company->logo_url; return view('companies.cart')->with(compact(['company', 'reviews', 'phones', 'groups', 'logo_url'])); } catch (\Exception $e) { return response()->view('errors.' . '503'); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(SosModelRequest $request) { $data = $request->all(); $user = User::findOrFail($request->input('user_id')); $sos = SosModel::create(['name' => date("ymdh"), 'user_id' => $request->input('user_id')]); $sos->companies()->attach($data["company_id"]); foreach ($data["company_id"] as $key => $company) { $company = Company::findOrFail($company); \Mail::send('emails.letter', compact('user', 'company'), function ($message) use($company, $user) { $message->to($company->email, env('MAIL_FROM_NAME'))->subject('Internship Letter'); }); } return redirect("/sos-requests"); }
public static function dailyUpdate() { $log = ''; //echo "<h1>Adding New Entities to Roster</h1>"; $log .= "Adding New Entities to Roster\n\n"; $capecod = '3'; $company = Company::findOrFail($capecod); $allowedSites = $company->siteList('1')->pluck('id')->toArray(); $allowedSites = Site::all()->pluck('id')->toArray(); $date = Carbon::now()->format('Y-m-d'); //$date = '2016-08-17'; $planner = SitePlanner::select(['id', 'site_id', 'entity_type', 'entity_id', 'task_id', 'from', 'to', 'days'])->where('from', '<=', $date)->where('to', '>=', $date)->whereIn('site_id', $allowedSites)->orderBy('site_id')->get(); foreach ($planner as $plan) { if ($plan->entity_type == 'c') { $site = Site::find($plan->site_id); $company = Company::findOrFail($plan->entity_id); $staff = $company->staffActive()->pluck('id')->toArray(); $log .= "\nf:" . $plan->from->format('Y-m-d') . ' t:' . $plan->to->format('Y-m-d') . ' [' . $plan->id . '] (' . $company->name . ") Task:{$plan->task_id} Site: {$site->name} ({$plan->site_id})\n"; foreach ($staff as $staff_id) { $user = User::findOrFail($staff_id); if (!$site->isUserOnRoster($staff_id, $date)) { //echo 'adding '.$user->fullname.' ('.$user->username.') to roster<br>'; $log .= 'adding ' . $user->fullname . ' (' . $user->username . ") to roster\n"; $newRoster = SiteRoster::create(array('site_id' => $site->id, 'user_id' => $staff_id, 'date' => $date . ' 00:00:00', 'created_by' => '1', 'updated_by' => '1')); } } } } //echo "<h1>Completed</h1>"; $log .= "\nCompleted"; $now = Carbon::now()->format('Y-m-d-G-i-s'); $bytes_written = File::put(public_path('filebank/log/nightly/' . $now . '.txt'), $log); if ($bytes_written === false) { die("Error writing to file"); } else { echo 'Logfile filebank/log/nightly/' . $now . '.txt'; } echo $log; }
public function getCompanyAttribute() { return \App\Models\Company::findOrFail($this->company_id); }
public function storeProfile(Request $request) { $companyID = $request->get('company_id'); $company = Company::findOrFail($companyID); $input = $request->all(); $company->fill($input)->save(); flash('Success', 'Profile successfully added!'); return redirect()->back(); }
/** * Get Company name from given id. * * @return \Illuminate\Http\Response */ public function getCompanyName($id) { $company = Company::findOrFail($id); return $company->name; }
/** * Get the PrincipleName (setter) */ public function getPrincipleNameAttribute() { if ($this->attributes['principle']) { return $this->attributes['principle']; } else { if ($this->attributes['principle_id']) { $company = Company::findOrFail($this->attributes['principle_id']); return $company->name; } } return; }
/** * Get Company Tasks options for 'select' dropdown in Vuejs format */ public function getCompanyTasks(Request $request, $company_id, $trade_id) { $company = Company::findOrFail($company_id); $array = []; $array[] = ['value' => '', 'text' => 'Select task']; // Create array in specific Vuejs 'select' format. $trade_count = count($company->tradesSkilledIn); foreach ($company->tradesSkilledIn as $trade) { $tasks = Task::where('trade_id', '=', $trade->id)->orderBy('name')->get(); foreach ($tasks as $task) { if ($task->status) { $text = $task->name; // If Trade_id supplied then only return tasks for that trade // - used for companies that have multiple trades if ($trade_id != 'all') { if ($trade_id != $trade->id) { continue; } } else { if ($trade_count > 1) { $text = $trade->name . ':' . $task->name; } } $array[] = ['value' => $task->id, 'text' => $text, 'name' => $task->name, 'code' => $task->code, 'trade_id' => $trade->id, 'trade_name' => $trade->name]; } } } return $array; }
public static function roster() { $log = ''; echo "<h2>Adding Users to Roster</h2>"; $log .= "Adding New Users to Roster\n"; $log .= "------------------------------------------------------------------------\n\n"; $allowedSites = Site::all()->pluck('id')->toArray(); if (Auth::check()) { $allowedSites = Auth::user()->company->siteList('1')->pluck('id')->toArray(); } $date = Carbon::now()->format('Y-m-d'); //$date = '2016-08-17'; $planner = SitePlanner::where('from', '<=', $date)->where('to', '>=', $date)->whereIn('site_id', $allowedSites)->orderBy('site_id')->get(); foreach ($planner as $plan) { if ($plan->entity_type == 'c') { $site = Site::find($plan->site_id); $company = Company::findOrFail($plan->entity_id); $staff = $company->staffActive()->pluck('id')->toArray(); $task = Task::find($plan->task_id); echo "<br><b>Site:{$site->name} ({$plan->site_id}) Company: {$company->name} Task: {$task->name} PID: {$plan->id}</b><br>"; $log .= "\nSite: {$site->name} ({$plan->site_id}) Company: {$company->name} Task: {$task->name} PID: {$plan->id}\n"; $found = false; foreach ($staff as $staff_id) { $user = User::findOrFail($staff_id); if (!$site->isUserOnRoster($staff_id, $date)) { echo 'adding ' . $user->fullname . ' (' . $user->username . ') to roster<br>'; $log .= 'adding ' . $user->fullname . ' (' . $user->username . ") to roster\n"; $newRoster = SiteRoster::create(array('site_id' => $site->id, 'user_id' => $staff_id, 'date' => $date . ' 00:00:00', 'created_by' => '1', 'updated_by' => '1')); $found = true; } } if (!$found) { echo "There were no users to add or they were already on the roster<br>"; $log .= "There were no users to add or they were already on the roster\n"; } } } echo "<h4>Completed</h4>"; $log .= "\nCompleted\n\n\n"; $bytes_written = File::append(public_path('filebank/log/nightly/' . Carbon::now()->format('Ymd') . '.txt'), $log); if ($bytes_written === false) { die("Error writing to file"); } }