本文整理汇总了PHP中app\models\Order::getRepository方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::getRepository方法的具体用法?PHP Order::getRepository怎么用?PHP Order::getRepository使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Order
的用法示例。
在下文中一共展示了Order::getRepository方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* @SWG\Api(
* path="/order/add",
* @SWG\Operation(
* nickname="Add new order",
* method="POST",
* summary="Add new order",
* notes="Returns order",
* type="Order",
* authorizations={},
* @SWG\Parameter(
* name="Body",
* description="Body",
* required=true,
* type="OrdersBody",
* paramType="body",
* allowMultiple=false
* ),
* @SWG\ResponseMessage(code=500, message="Internal server error")
* )
* )
*/
public function add()
{
$statusCode = 200;
$params = \Input::all();
if ($params) {
$errors = [];
$mainValidator = Validator::make($params, ['customer_id' => 'required|numeric|exists:customers,id', 'total' => 'required|numeric|min:1', 'items' => 'required|array']);
if ($mainValidator->fails()) {
$response = ['error' => ['main' => $mainValidator->errors()]];
$statusCode = 500;
} else {
$itemsValidator = [];
$itemsAddonsValidator = [];
foreach ($params['items'] as $itemKey => $item) {
$itemsValidator[$itemKey] = Validator::make($item, ['photo_id' => 'required|numeric|exists:photos,id', 'qty' => 'required|numeric|min:1', 'price_per_item' => 'required|numeric', 'format_id' => 'required|numeric|exists:formats,id', 'addons' => 'required|array']);
foreach ($item['addons'] as $addon) {
$itemsAddonsValidator[$itemKey][] = Validator::make($addon, ['id' => 'required|numeric|exists:addons,id', 'qty' => 'required|numeric|min:1']);
}
}
foreach ($itemsValidator as $itemKey => $validator) {
if ($validator->fails()) {
$errors['items'][$itemKey + 1] = $validator->errors();
} else {
foreach ($itemsAddonsValidator[$itemKey] as $addonKey => $validator) {
if ($validator->fails()) {
$errors['items'][$itemKey + 1]['addons'][$addonKey + 1] = $validator->errors();
}
}
}
}
if ($errors) {
$response = ['error' => $errors];
$statusCode = 500;
} else {
$orderModel = new Models\Order();
$orderModel->getRepository()->saveFromArray($params);
$orderView = new ModelViews\Order($orderModel);
$response = $orderView->get();
}
}
} else {
$response = ['error' => 'Empty or invalid body'];
$statusCode = 500;
}
return \Response::json($response, $statusCode);
}