本文整理汇总了PHP中app\Student::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Student::validate方法的具体用法?PHP Student::validate怎么用?PHP Student::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Student
的用法示例。
在下文中一共展示了Student::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$validator = $this->student->validate($request);
if ($validator->fails()) {
$student = json_decode(json_encode($request->all()), FALSE);
$html = view('students._form', compact('student'))->withErrors($validator);
return response()->json(['status' => 0, 'html' => $html->render()]);
}
$this->student->findOrFail($id)->update($request->except('student_code'));
return response()->json(['status' => 1, 'message' => 'success']);
}
示例2: update
public function update($id, Request $request)
{
//------Validation-------
$validator = Student::validate();
if ($validator->fails()) {
return redirect()->route('students.edit', array('id' => $id))->withErrors($validator)->withInput();
}
//-----End Validation-----
try {
$student = Student::findOrFail($id);
} catch (Exception $e) {
App::abort(404);
//if student details not found in the database
}
$student->fill($request->input());
//Display flash msg on successful updation
if ($student->save()) {
if (is_null($request->input("interests"))) {
//no interests then remove from pivot table, (by passing an empty array)
$student->interests()->sync(array());
} else {
//if saving of student is successful and interests is not null sync interests
$student->interests()->sync($request->input("interests"));
}
Session::flash('message', "Student '" . $student->name . "' updated successfully. ");
return redirect()->route('students.index');
} else {
Session::flash('message', "Updating student unsuccessful.");
return redirect()->route('students.index');
}
}