本文整理汇总了PHP中app\models\Item::onlyTrashed方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::onlyTrashed方法的具体用法?PHP Item::onlyTrashed怎么用?PHP Item::onlyTrashed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Item
的用法示例。
在下文中一共展示了Item::onlyTrashed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: restoreItem
/**
* RESTORE an item
*
* (the model migth allow soft deletes!)
*
* Make sure the new sequence number fits sequentially into
* the list of sequence numbers of the existing items for a plan
* and that all current sequence numbers are in 1.0 steps
*
* @param object $items
* @param number $new_seq_no
*/
function restoreItem($id)
{
// this item should be restored
$item = Item::onlyTrashed()->find($id);
if (!$item) {
return false;
}
$item->restore();
// get all items of the related plan
$plan = Plan::find($item->plan_id);
$items = $plan->items()->orderBy('seq_no')->get();
// numbering them countering with 1.0
$counter = 1.0;
foreach ($items as $item) {
if ($item->seq_no != $counter) {
$i = Item::find($item->id);
# get the actual DB record
$item->seq_no = $counter;
# update the current selection
$i->seq_no = $counter;
# update the seq_no
$i->save();
# save the record
}
$counter += 1.0;
}
return true;
}
示例2: restoreAllTrashed
/**
* RESTORE all trashed items of a plan
*
*/
public function restoreAllTrashed($plan_id)
{
// this item should be restored
$items = Item::onlyTrashed()->where('plan_id', $plan_id)->get();
if (!$items) {
return false;
}
// restore all items and try to restore their correct sequence number
foreach ($items as $item) {
restoreItem($item->id);
}
flash('All trashed items restored. Please review the sequence!');
return \Redirect::back();
}
示例3: edit
/**
* PLAN DETAILS form
*
* @param int $id
* @param int $new_item_id indicates a newly inserted item
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
// find a single plan by ID
$plan = Plan::with(['items' => function ($query) {
$query->withTrashed()->orderBy('seq_no');
}])->find($id);
if ($plan) {
// get list of service types
$types = Type::get();
// get list of users
$users = User::orderBy('first_name')->get();
// get list of trashed items (if any)
$trashedItemsCount = Item::onlyTrashed()->where('plan_id', $id)->count();
// check if a new item was just now inserted (used for highlighing in the view)
$newest_item_id = 0;
if (session()->has('newest_item_id')) {
$newest_item_id = session()->get('newest_item_id');
session()->forget('newest_item_id');
}
// get service times from plan dates
$plan->start = Carbon::instance($plan->date)->toTimeString();
// for backwards compatibility, we allowed for null as end date
if ($plan->date_end) {
$plan->end = Carbon::instance($plan->date_end)->toTimeString();
} else {
$plan->end = "23:59";
}
return view($this->view_one, array('plan' => $plan, 'types' => $types, 'users' => $users, 'versionsEnum' => json_decode(env('BIBLE_VERSIONS')), 'newest_item_id' => $newest_item_id, 'trashedItemsCount' => $trashedItemsCount));
}
flashError('Plan with id "' . $id . '" not found');
return \Redirect::route($this->view_idx);
}