本文整理汇总了PHP中app\models\Contact::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Contact::findOrFail方法的具体用法?PHP Contact::findOrFail怎么用?PHP Contact::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Contact
的用法示例。
在下文中一共展示了Contact::findOrFail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: seenContact
public function seenContact($id)
{
if (Request::ajax()) {
$result['error'] = false;
try {
$contact = Contact::findOrFail($id);
$contact->seen = $contact->seen ? 0 : 1;
$contact->save();
} catch (ModelNotFoundException $e) {
$result['error'] = true;
}
return response()->json($result);
}
}
示例2: edit
public function edit($id)
{
$contact = Contact::findOrFail($id);
if (Request::isMethod('get')) {
return view('admin.contact_edit', ['contact' => $contact]);
}
$validator = Validator::make(Request::all(), $this->rules);
if ($validator->fails()) {
return redirect()->route('contact_edit', [$id])->withInput()->withErrors($validator);
}
$contact->country = Request::input('country');
$contact->countryEng = Request::input('countryEng');
$contact->address = Request::input('address');
$contact->addressEng = Request::input('addressEng');
$contact->phone = Request::input('phone');
$contact->email = Request::input('email');
$contact->enabled = Request::has('enabled');
$contact->save();
return redirect()->route('contact_edit', [$id])->with('msg', 'Изменения сохранены');
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param int $id
*
* @return Response
*/
public function update($id, Request $request)
{
$contact = Contact::findOrFail($id);
$contact->update($request->all());
Session::flash('flash_message', 'Contact updated!');
return redirect('contacts');
}