本文整理匯總了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');
}