本文整理汇总了PHP中app\models\Category::withTrashed方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::withTrashed方法的具体用法?PHP Category::withTrashed怎么用?PHP Category::withTrashed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::withTrashed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editCategory
public function editCategory()
{
$data = \Input::all();
$id = $data['id'];
$name = $data['name'];
$exist = Category::withTrashed()->where('id', '!=', $id)->where('name', '=', $name)->get()->first();
if ($exist) {
$retData['data'] = $exist;
$retData['status'] = 409;
} else {
$category = Category::find($id);
$category->name = $name;
$category->parent_id = $data['parent_id'];
$retData['status'] = $category->save() ? 200 : 500;
}
return \Response::json($retData);
}
示例2: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// Videos
echo 'UPDATING VIDEOS', PHP_EOL, '===============', PHP_EOL;
$count = 0;
Video::withTrashed()->with('category')->chunk(200, function ($videos) use($count) {
foreach ($videos as $v) {
echo 'Updating Video with ID: ', $v->id, PHP_EOL;
$v->detag();
// quick and dirty. not 100% correct though.
if ($v->category->shortname === 'pr0n') {
$v->tag('nsfw');
} else {
$v->tag('sfw');
}
$v->tag(array_filter([$v->category->shortname, $v->category->name, $v->interpret, $v->songtitle, $v->imgsource], function ($elem) {
return !empty(trim($elem));
}));
$count++;
}
});
echo PHP_EOL, PHP_EOL, 'Updated ', $count, ' Videos.', PHP_EOL, PHP_EOL, PHP_EOL;
// User filters
echo 'UPDATING USERS', PHP_EOL, '==============', PHP_EOL;
$count = 0;
$categories = Category::withTrashed()->get()->keyBy('id');
User::withTrashed()->chunk(200, function ($users) use(&$count, $categories) {
foreach ($users as $u) {
echo 'Updating User: ', $u->username, PHP_EOL;
$u->categories = array_values($categories->filter(function ($cat) use($u) {
return !in_array($cat->id, $u->categories);
})->map(function ($cat) {
return $cat->shortname;
})->all());
$u->save();
$count++;
}
});
echo PHP_EOL, PHP_EOL, 'Updated ', $count, ' Users.', PHP_EOL, PHP_EOL, PHP_EOL;
}