當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Set::find方法代碼示例

本文整理匯總了PHP中Set::find方法的典型用法代碼示例。如果您正苦於以下問題:PHP Set::find方法的具體用法?PHP Set::find怎麽用?PHP Set::find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Set的用法示例。


在下文中一共展示了Set::find方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 public function run()
 {
     DB::table('items')->delete();
     $set = Set::find(1);
     $item1 = Item::create(array('item_id' => 1, 'name' => 'ATH-M50x Professional Monitor Headphones', 'creator' => 1, 'image_url' => 'https://d2qmzng4l690lq.cloudfront.net/resizer/450x450/v/VDWZ23_20140202_100823_2E9CC3160EB4DE7586.png'));
     $item1->sets()->attach(1);
     sleep(1);
     $item2 = Item::create(array('item_id' => 2, 'name' => 'FiiO E17 USB DAC Headphone Amplifier', 'creator' => 1, 'image_url' => 'https://d2qmzng4l690lq.cloudfront.net/resizer/450x450/v/2FNXFT_20130816_132147_OPWOOEWLU125PK8HXM.png'));
     $item2->sets()->attach(1);
     sleep(1);
     $item3 = Item::create(array('item_id' => 3, 'name' => 'iBasso DX50 Digital Audio Player', 'creator' => 1, 'image_url' => 'https://d2qmzng4l690lq.cloudfront.net/resizer/450x450/v/EJ6QKT_20140530_194403_0F8FDF5FA221AAC02E.png'));
     $item3->sets()->attach(1);
 }
開發者ID:heekah7,項目名稱:massdrop,代碼行數:13,代碼來源:ItemTableSeeder.php

示例2: removeItem

 /**
  * Remove an item from a set.
  * e.g. curl -i --user a@aa.com:a1\! -X DELETE localhost:8000/api/v1/set/1/item/1
  *
  * @param  int $setId
  * @param  int $itemId
  * @return Response
  */
 public function removeItem($setId, $itemId)
 {
     $set = Set::find($setId);
     $item = Item::find($itemId);
     if (!is_object($set)) {
         // Return 404 Not Found if the set does not exist
         return Response::json(array('errors' => array("The set does not exist")), 404);
     } else {
         if (!is_object($item)) {
             // Return 404 Not Found if the item does not exist
             return Response::json(array('errors' => array("The item does not exist")), 404);
         } else {
             if ($set->creator != Auth::user()->user_id) {
                 // Return 401 Unauthorized if the set was not created by the authenticated user
                 return Response::json(null, 401);
             } else {
                 if (!$set->items->contains($itemId)) {
                     // Return 404 Not Found if the set does not contain the item
                     return Response::json(array('errors' => array("The set already contains that item")), 404);
                 } else {
                     if ($set->items()->count() < 2) {
                         // Return 409 Conflict if this is the only item left in the set
                         return Response::json(array('errors' => array("You cannot remove the only item in a set")), 409);
                     } else {
                         // Attach the item to the set
                         $set->items()->detach($itemId);
                     }
                 }
             }
         }
     }
 }
開發者ID:heekah7,項目名稱:massdrop,代碼行數:40,代碼來源:SetController.php


注:本文中的Set::find方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。