本文整理匯總了PHP中Price::scope方法的典型用法代碼示例。如果您正苦於以下問題:PHP Price::scope方法的具體用法?PHP Price::scope怎麽用?PHP Price::scope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Price
的用法示例。
在下文中一共展示了Price::scope方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: save
private function save($publicId = null)
{
if ($publicId) {
$product = Product::scope($publicId)->firstOrFail();
} else {
$product = Product::createNew();
}
$product->product_key = trim(Input::get('product_key'));
$product->notes = trim(Input::get('notes'));
$product->pack_types = trim(Input::get('pack_types'));
$product->ice = trim(Input::get('ice'));
$product->units = trim(Input::get('units'));
$product->cc = trim(Input::get('cc'));
$product->save();
$data = json_decode(Input::get('data'));
$pricesIds = [];
$id = 1;
foreach ($data->prices as $price) {
if (isset($price->public_id) && $price->public_id) {
$record = Price::scope($price->public_id)->firstOrFail();
} else {
$record = Price::createNew();
}
$record->price_type_id = $id;
$record->cost = trim($price->cost);
$product->prices()->save($record);
$priceIds[] = $record->public_id;
$id++;
}
foreach ($product->prices as $price) {
if (!in_array($price->public_id, $priceIds)) {
$price->delete();
}
}
if ($publicId) {
Session::flash('message', trans('texts.updated_product'));
} else {
// Activity::createProduct($product);
Session::flash('message', trans('texts.created_product'));
}
return Redirect::to('products/' . $product->public_id);
}