當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。