/** * Execute the console command. * * @return mixed */ public function handle() { $user = User::first(); if (!$user) { $this->error('No user to import articles to'); return; } $archives = PostCategory::where('name', 'archives')->first(); if (!$archives) { $archives = PostCategory::create(['name' => 'archives', 'description' => 'old posts from prev site']); } $this->archiveId = $archives->id; $upperBound = intval($this->ask('What is the upper bound for the article ids?')); $articlesToFetch = collect(ImportResult::getMissingIdsUpToLimit($upperBound)); $articlesToFetch->each(function ($id) use($user) { try { $reader = $this->articleReader->getPage($id); $this->import($reader, $id, $user); ImportResult::create(['article_id' => $id, 'imported' => 1]); } catch (\Exception $e) { $this->error('Failed on article ' . $id . ' : ' . $e->getMessage()); ImportResult::create(['article_id' => $id, 'imported' => 0]); } }); }
public function store(Request $request) { $category = PostCategory::create($request->only(['name', 'description'])); return redirect('admin/blog/categories/' . $category->id . '/posts'); }