当前位置: 首页>>代码示例>>PHP>>正文


PHP Student::validate方法代码示例

本文整理汇总了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']);
 }
开发者ID:saphira145,项目名称:laravelApp,代码行数:18,代码来源:StudentsController.php

示例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');
     }
 }
开发者ID:hemant6488,项目名称:Laravel-StudentManagementSystem,代码行数:31,代码来源:StudentController.php


注:本文中的app\Student::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。