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


PHP User::findOrFail方法代码示例

本文整理汇总了PHP中App\Model\User::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findOrFail方法的具体用法?PHP User::findOrFail怎么用?PHP User::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在App\Model\User的用法示例。


在下文中一共展示了User::findOrFail方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: deleteUser

 /**
  * Finds a user and soft deletes it
  *
  * @param int $userId
  *
  * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
  *
  * @return null
  */
 public static function deleteUser($userId)
 {
     $user = User::findOrFail($userId);
     if ($user) {
         $user->delete();
     } else {
         throw \Illuminate\Database\Eloquent\ModelNotFoundException;
     }
 }
开发者ID:Munk91,项目名称:Hovedopgave,代码行数:18,代码来源:UserRepository.php

示例2: dispatch

 public function dispatch(Request $request, Response $response, $args)
 {
     $user = $this->container->get('currentUser');
     $id = isset($args['id']) ? (int) $args['id'] : null;
     $notes = [];
     if ($id) {
         $note = Note::where('id', $id)->where('user_id', $user->userId)->firstOrFail();
         $notes = [$note];
     } else {
         $notes = User::findOrFail($user->userId)->notes;
     }
     return $response->write(json_encode(['message' => 'List of Notes', 'data' => $notes]));
 }
开发者ID:aodkrisda,项目名称:notes-api,代码行数:13,代码来源:IndexAction.php

示例3: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     /**
      * Thực hiện tìm và xóa TK theo id truyền vào
      * Nếu lỗi chuyển hướng
      */
     try {
         $user = User::findOrFail($id)->delete();
         return redirect('admin/user-manager');
     } catch (Exception $e) {
         return abort(404);
     }
 }
开发者ID:viethoang0703,项目名称:blogs,代码行数:19,代码来源:AdminController.php

示例4: update

 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $from = $request->input('from', '');
     $to = $request->input('to', '');
     if (empty($id) || $from === '' || $to === '') {
         return new Response("Mandatory parameter(s) are missing.", 405);
     }
     try {
         if ($id > 0) {
             $user = User::findOrFail($id);
             $old_desk = $user->desk;
         } else {
             if ($id < 0) {
                 // Busy Flag
                 $old_desk = Desk::find($from);
             } else {
                 return new Response("Invalid user id.", 405);
             }
         }
         #print_r( $old_desk->toArray() );
         if ($old_desk != null && $from != $old_desk->id) {
             return new Response("Out of sync, user was moved someplace else already.", 409);
         }
         if ($to != 0) {
             $new_desk = Desk::findOrFail($to);
             if (!$this->checkEmptyDesk($new_desk)) {
                 return new Response("Out of sync, target desk is not empty.", 409);
             }
         } else {
             $id = 0;
         }
         $ret = [];
         if ($old_desk != null) {
             $old_desk->users_id = 0;
             $old_desk->save();
             $ret['old'] = $old_desk->toArray();
         }
         if (isset($new_desk)) {
             $new_desk->users_id = intval($id);
             $new_desk->save();
             $ret['new'] = $new_desk->toArray();
         }
         return response()->json($ret);
     } catch (\Exception $e) {
         return new Response("There was an error while processing the update request: " . $e->getMessage(), 500);
     }
 }
开发者ID:angeli,项目名称:people,代码行数:54,代码来源:UserController.php

示例5: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     $user = User::findOrFail($id);
     $user->delete();
     return redirect()->action('UserController@index');
 }
开发者ID:joceline-putra,项目名称:ecommerce-laravel,代码行数:13,代码来源:UserController.php


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