本文整理汇总了PHP中app\models\Item::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::findOrFail方法的具体用法?PHP Item::findOrFail怎么用?PHP Item::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Item
的用法示例。
在下文中一共展示了Item::findOrFail方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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)
{
$item = Item::findOrFail($id);
foreach (array_keys(array_except($this->fields, ['item'])) as $field) {
$item->{$field} = $request->get($field);
}
$item->save();
return redirect("/admin/item/{$id}/edit")->withSuccess("修改完成!");
}
示例2: updateTableActions
/**
* Ajax call for update favorite column
*
* @param Request $request
* @return array
*/
public function updateTableActions(Request $request)
{
if ($request->get('action') == 'favorite') {
$item = Item::findOrFail($request->get('book-id'));
$favorite = !$item->favorite;
$item->update(['favorite' => $favorite]);
if ($item->favorite) {
$data['sweetalert'] = ['title' => 'το βιβλίο προστέθηκε στα Αγαπημένα', 'level' => 'success'];
} else {
$data['sweetalert'] = ['title' => 'το βιβλίο ΔΕΝ ανήκει πλέον στα Αγαπημένα', 'level' => 'info'];
}
$data['itemId'] = $item->id;
$data['itemFavorite'] = $item->favorite;
} elseif ($request->get('action') == 'delete') {
$item = Item::findOrFail($request->get('book-id'));
if ($item->delete()) {
$data['sweetalert'] = ['title' => 'το βιβλίο Διεγράφηκε...', 'level' => 'success'];
}
}
return $data;
}
示例3: scopePublish
public function scopePublish()
{
Item::findOrFail($this->organizations->first()->pivot->id)->update(['published' => 1]);
}
示例4: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$item = Item::findOrFail($id);
$data = ['id' => $id];
foreach (array_keys($this->fields) as $field) {
$data[$field] = old($field, $item->{$field});
}
return view('admin.item.edit', ['data' => $data]);
}
示例5: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$list = Item::findOrFail($id);
$list->delete();
return redirect()->route('service.index', compact('list'))->withMessage('Service has been Deleted')->withStatus('success');
}
示例6: update
/**
*
* @param Request $request
* @param Item $item
* @return Response
*/
public function update(Request $request, Item $item)
{
if ($request->has('updatingNextTimeForRecurringItem')) {
$item = $this->itemsRepository->updateNextTimeForRecurringItem($item);
} else {
$data = array_compare($item->toArray(), $request->only(['priority', 'urgency', 'title', 'body', 'favourite', 'pinned', 'alarm', 'not_before', 'recurring_unit', 'recurring_frequency']));
//So the recurring unit can be removed
if ($request->get('recurring_unit') === 'none') {
$data['recurring_unit'] = null;
}
//So the not before time can be removed
if ($request->exists('not_before') && !$request->get('not_before')) {
$data['not_before'] = null;
}
//So the recurring frequency can be removed
if ($request->get('recurring_frequency') === '') {
$data['recurring_frequency'] = null;
}
//So the alarm of an item can be removed
if ($request->has('alarm') && !$request->get('alarm')) {
$data['alarm'] = null;
}
//So the urgency of an item can be removed
if ($request->has('urgency') && !$request->get('urgency')) {
$data['urgency'] = null;
}
$item->update($data);
if ($request->has('parent_id')) {
//So the parent_id can be removed (so the item moves to the top-most level, home)
if ($request->get('parent_id') === 'none') {
$item->parent()->dissociate();
} else {
$item->parent()->associate(Item::findOrFail($request->get('parent_id')));
}
$item->save();
}
if ($request->has('category_id')) {
$item->category()->associate(Category::findOrFail($request->get('category_id')));
$item->save();
}
if ($request->has('moveItem')) {
$this->itemsRepository->moveItem($request, $item);
}
}
$item = $this->transform($this->createItem($item, new ItemTransformer()))['data'];
return response($item, Response::HTTP_OK);
}
示例7: othercode
public function othercode($id)
{
$item = Item::findOrFail($id);
$items = OtherBarcode::where('item_id', $id)->get();
return view('item.othercode', compact('item', 'items'));
}