本文整理汇总了PHP中app\models\Company::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Company::findOrFail方法的具体用法?PHP Company::findOrFail怎么用?PHP Company::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Company
的用法示例。
在下文中一共展示了Company::findOrFail方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* 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');
}
}
示例2: cart
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');
}
}
示例3: store
/**
* 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");
}
示例4: dailyUpdate
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;
}
示例5: getCompanyAttribute
public function getCompanyAttribute()
{
return \App\Models\Company::findOrFail($this->company_id);
}
示例6: storeProfile
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();
}
示例7: getCompanyName
/**
* Get Company name from given id.
*
* @return \Illuminate\Http\Response
*/
public function getCompanyName($id)
{
$company = Company::findOrFail($id);
return $company->name;
}
示例8: getPrincipleNameAttribute
/**
* 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;
}
示例9: getCompanyTasks
/**
* 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;
}
示例10: roster
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");
}
}