本文整理汇总了PHP中app\Item::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::firstOrNew方法的具体用法?PHP Item::firstOrNew怎么用?PHP Item::firstOrNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Item
的用法示例。
在下文中一共展示了Item::firstOrNew方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: items
public function items()
{
$cdn_ver = '5.16.1';
$json = file_get_contents('https://global.api.pvp.net/api/lol/static-data/euw/v1.2/item?itemListData=all&api_key=2767f871-228a-412a-9063-d754163404f4');
$obj = json_decode($json);
$items = array();
foreach ($obj->data as $item) {
$it = Item::firstOrNew(['riot_id' => $item->id, 'name' => $item->name]);
$it->icon = 'http://ddragon.leagueoflegends.com/cdn/' . $cdn_ver . '/img/item/' . $item->image->full;
$it->description = $item->sanitizedDescription;
$it->plaintext = isset($item->plaintext) ? $item->plaintext : '';
$it->group = isset($item->group) ? $item->group : '';
$it->gold_base = $item->gold->base;
$it->gold_total = $item->gold->total;
$it->depth = isset($item->depth) ? $item->depth : 0;
$it->save();
$tags = array();
if (isset($item->tags)) {
foreach ($item->tags as $tag) {
$new_tag = ItemTags::firstOrNew(['item_id' => $item->id, 'name' => $tag]);
$new_tag->save();
array_push($tags, $new_tag);
}
}
$froms = array();
if (isset($item->from)) {
foreach ($item->from as $from) {
$new_from = ItemFrom::firstOrNew(['item_id' => $item->id, 'other_item_id' => $from]);
$new_from->save();
array_push($froms, $new_from);
}
}
$intos = array();
if (isset($item->into)) {
foreach ($item->into as $into) {
$new_into = ItemInto::firstOrNew(['item_id' => $item->id, 'other_item_id' => $into]);
$new_into->save();
array_push($intos, $new_into);
}
}
// And now, get the maps at which it can be used
$it->itemTags = $tags;
$it->itemFrom = $froms;
$it->itemInto = $intos;
array_push($items, $it);
}
return $items;
}
示例2: saveRecentList
public function saveRecentList($flag, $storeId, $itemInfoIds, $qtys)
{
$recentList = RecentList::firstOrNew(['user_id' => $this->id]);
$recentList->store_id = $storeId;
$recentList->save();
// list is saved;
//delete old items
RecentListItem::where('recent_list_id', $recentList->id)->delete();
// delete old items
//add new items
foreach ($itemInfoIds as $i => $infoId) {
$item = Item::firstOrNew(['item_info_id' => $infoId, 'store_id' => $storeId]);
if (!isset($item->price)) {
$item->price = 0;
$item->save();
}
//create recentItems;
RecentListItem::create(['item_id' => $item->id, 'recent_list_id' => $recentList->id, 'qty' => $qtys[$i]]);
}
}