本文整理汇总了PHP中app\Item::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::with方法的具体用法?PHP Item::with怎么用?PHP Item::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Item
的用法示例。
在下文中一共展示了Item::with方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeComment
public function storeComment($itemId, Request $request)
{
$item = Item::with('comments.user')->findOrFail($itemId);
$comment = new Comment(['user_id' => $request->userId, 'message' => $request->message]);
$newComment = $item->comments()->save($comment);
$result = Comment::with('user')->findOrFail($newComment->id);
event(new UserPostedAComment($result));
return $result;
}
示例2: show
public function show($id)
{
$list = Dramalist::find($id);
$list->load(['user' => function ($query) {
$query->select('id', 'name');
}]);
$items = Item::with(['drama' => function ($query) {
$query->select('id', 'title', 'type', 'era', 'genre', 'original', 'count', 'state', 'sc', 'poster_url');
}, 'episode' => function ($query) {
$query->select('id', 'title', 'alias', 'release_date', 'duration', 'poster_url');
}])->select('id', 'no', 'drama_id', 'episode_id', 'review', 'created_at', 'updated_at')->where('list_id', $id)->orderBy('no')->paginate(20);
return view('list.show', ['list' => $list, 'items' => $items]);
}
示例3: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$start = microtime(true);
$collection = Item::with('files')->search($this->argument('term'))->get()->take($this->argument('results'));
$rows = [];
foreach ($collection as $item) {
$path = $item->path;
$rows[] = ['Item', $item->title, $path];
foreach ($item->files as $file) {
$rows[] = ['File', "- {$file->filename}", "{$path}/{$file->filename}"];
}
}
$end = microtime(true);
$this->table(['type', 'filename', 'path'], $rows);
$this->line("Took " . round($end - $start, 3) . "s to search");
}
示例4: getEdit
public function getEdit($id = null)
{
$item = \App\Item::with('stores')->find($id);
//Get data for the item to be edited
$amounts_for_dropdown = [0, 25, 50, 75, 100];
$locations_for_dropdown = ['Aisle', 'Bakery', 'Bulk', 'Dairy', 'Meat', 'Produce', 'Seafood', 'Specialty'];
$storeModel = new \App\Store();
//Call the model to get an array of all the possible stores with their id
$stores_for_checkbox = $storeModel->getStoresForCheckboxes();
$stores_for_this_item = [];
foreach ($item->stores as $store) {
//Create an array of store names for this food item
$stores_for_this_item[] = $store->name;
}
return view('items.edit')->with(['item' => $item, 'amounts_for_dropdown' => $amounts_for_dropdown, 'locations_for_dropdown' => $locations_for_dropdown, 'stores_for_checkbox' => $stores_for_checkbox, 'stores_for_this_item' => $stores_for_this_item]);
}
示例5: demo
public function demo()
{
$new_items = Item::with('itemTags', 'itemInto.item', 'itemFrom.item', 'itemMaps')->get();
return View::make('item.alldemo')->with('items', $new_items);
}
示例6: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$categories = $this->categories;
try {
$item = Item::with('images')->findOrFail($id);
} catch (ModelNotFoundException $ex) {
Flash::error('No item found' . $ex);
return redirect()->route('store.items.index');
}
return view('store.items.edit', compact('item', 'categories'));
}