当前位置: 首页>>代码示例>>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;未经允许,请勿转载。