本文整理汇总了PHP中app\Item::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::findOrFail方法的具体用法?PHP Item::findOrFail怎么用?PHP Item::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Item
的用法示例。
在下文中一共展示了Item::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
$bomhead = Bomhead::findOrNew($id);
$parentItem = Item::findOrFail($id);
$bomitems = Bomitem::latest('created_at')->where('parent_item_id', $id)->with('parentitem')->get();
return view('boms.edit', compact('bomhead', 'parentItem', 'bomitems'));
}
示例2: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, Request $request)
{
$this->validate($request, ['id' => 'required']);
$item = Item::findOrFail($id);
$item->update($request->all());
Session::flash('flash_message', 'Item successfully updated!');
return redirect('item');
}
示例3: unlike
public function unlike($item, $userId)
{
$item = Item::findOrFail($item);
if ($item->unlike($userId)) {
event(new UserUnlikedAnItem($item));
return 'You unliked an item.';
}
return 'There was a problem unliking a post.';
}
示例4: delete
public function delete(Request $request)
{
$item = Item::findOrFail($request->id);
$item->delete_stat = 1;
$item->save();
$itemid = $item->id;
$employeeid = Auth::user()->id;
$logs = ActivityLog::create(['employee_id' => $employeeid, 'activity' => 'Delete Item', 'table_affected' => 'item', 'primary_key' => $itemid, 'column_affected' => 'remove_stat']);
return redirect()->route('erp_system.item.index')->withSuccess('Item deleted.');
}
示例5: postIndex
public function postIndex()
{
$id = Input::get('id');
//findOrFail is a method provided by Eloquent (in item model)
$item = Item::findOrFail($id);
if ($item->owner_id == Auth::user()->id) {
//only mark it when the logged in user is the owner
$item->mark();
}
return Redirect::route('home');
}
示例6: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$item = Item::findOrFail($id);
$item = $this->getRequestItem($request, $item);
//// category object
$category = new Category();
$category->name = $request->get('category');
$category->container_id = $request->get('container_id');
$item = Item::persist($item, $category)->toArray();
$item['category'] = $category->name;
return $item;
}
示例7: toggleDone
public function toggleDone($id)
{
$item = Item::findOrFail($id);
if ($item->status == 0) {
$item->status = 1;
$item->update();
return true;
} else {
$item->status = 0;
$item->update();
return true;
}
return false;
}
示例8: markAsFavorite
/**
* [markAsFavorite mark a podcast item as favorite]
* @return array
*/
public function markAsFavorite()
{
$result['status'] = 0;
$result['message'] = 'Something went wrong, please try again';
$itemId = trim(strip_tags(Request::get('itemId')));
$item = DB::table('items')->select('user_id')->where('user_id', '=', Auth::user()->id)->where('id', '=', $itemId)->first();
// if item with id exists in DB and is owned by the authenticated user
if ($item) {
$podcastItem = Item::findOrFail($itemId);
$result['currentValue'] = !$podcastItem->is_mark_as_favorite;
$podcastItem->is_mark_as_favorite = !$podcastItem->is_mark_as_favorite;
// opposite of current value
$podcastItem->save();
$result['status'] = 1;
$result['message'] = 'This item has been updated';
}
return $result;
}
示例9: getFiles
public function getFiles(ItemRequest $request)
{
$item = Item::findOrFail($request->get('item_id'));
$list = [];
$size = 0;
// foreach ($item->items as $item) {
// $list[] = [
// 'file' => $item->title,
// 'path' => $item->path,
// 'id' => $item->id,
// ];
// }
foreach ($item->files()->get() as $file) {
$size += $file->size;
$list[] = ['file' => $file->filename, 'path' => "{$item->path}/{$file->filename}", 'size' => $this->formatBytes($file->size)];
}
return response()->json(['files' => $list, 'count' => count($list), 'size' => $this->formatBytes($size)]);
}
示例10: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$item = \App\Item::findOrFail($id);
$item->delete();
return 'The resource #' . $id . ' was deleted';
}
示例11: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(ItemRequest $request, $id)
{
$item = Item::findOrFail($id);
$item->update($request->all());
$prices = Price::where('item_id', '=', $id)->orderBy('sellable')->get();
foreach ($prices as $price) {
if ($price->custom_price < $item->minimum_price) {
$price->sellable = 0;
$price->save();
} else {
$price->sellable = 1;
$price->save();
}
if ($price->is_custom == '0') {
$price->custom_price = $item->price;
$price->save();
}
}
return redirect('item')->with('message', 'Data berhasil dirubah!');
}
示例12: show
/**
*
* Show - Show the contents of a particular item
* Parameter - Id # of specific item
*/
public function show($id)
{
$item = Item::findOrFail($id);
return view('items.show', compact('item'));
}
示例13: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$data = $request->except('_token');
$item = Item::findOrFail($id);
$path = 'images/items/';
$destinationPath = public_path($path);
if ($request->hasFile('image_url')) {
$name = $request->file('image_url')->getClientOriginalName();
$request->file('image_url')->move($destinationPath, $name);
$item->image_url = $path . $name;
}
$item->name = $data['name'];
$item->status = (int) $data['status'];
$item->qualtity = $data['quantity'];
$item->save();
return redirect()->route('admin.item.show', $item->id)->with(['message' => 'success!']);
}
示例14: update
public function update($id, ItemRequest $request)
{
$item = Item::findOrFail($id);
$item->update($request->all());
return redirect('items');
}
示例15: edit
public function edit(Requests\UpdateItemRequest $request)
{
$item = Item::findOrFail($request->item_id);
return view('product.edititem', compact('item'));
}