/** * Execute the console command. * * @return mixed */ public function handle() { $this->scraper = new Scraper(); $this->postRepository = new PostRepository(new Post()); $this->info("Fetching posts from vdm..."); $posts = $this->scraper->scrap(200); $this->info(sprintf("Saving %d posts.", Arrays::size($posts))); Arrays::each($posts, function ($post) { $this->postRepository->create($post->toArray()); }); $this->info("Done."); }
/** * @param array $data * @param int|null $id */ protected function savePost(array $data = [], $id = null) { // Image Handling if (isset($data['image'])) { $data['image'] = $this->buildImage($data['slug'], $data['image']); } // We create the Post if ($id === null) { $data['author_id'] = Auth::id(); $this->posts->create($data); } else { $this->posts->update($data, $id); } }
/** * Store a newly created resource in storage. * * @param PostRequest|Request $request * @return \Illuminate\Http\Response */ public function store(PostRequest $request) { $this->repository->create($request->all()); return redirect()->route('admin.post.index'); }