本文整理汇总了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);
}
示例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);
}
}
}
}
}
}