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); }
/** * 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: '******'Updated ', $count, ' Users.', PHP_EOL, PHP_EOL, PHP_EOL; }