public function getPostsFromSource($source) { $this->info("Getting posts from [ " . $source . " ]"); // Check if it's a valid source if (!Source::has($source)) { throw new Exception("Given Shorthand is not for a valid source", 1); } // If exists, proceed $source = Source::where('shorthand', $source)->first(); // get post links $postLinks = (new PostListGetter($source))->getList(); // get details for each link foreach ($postLinks as $key => $link) { $this->info('Getting details for link: ' . $link); $details = (new PostDetailsGetter($source, $link))->getDetails(); if ($details) { if (!$source->hasPublished($details['url'])) { // save // queue image for processing // save the post $post = Post::create($details); // associate the post to a source $post->source()->associate($source)->save(); // extract and process images (if any); (new \App\ContentProcessors\ImageProcessors\MainProcessor($post))->process(); // process text (new \App\ContentProcessors\TextProcessors\MainProcessor($post))->process(); } else { $this->info('This post is already in the database'); } } else { $this->info('could not extract content from this url'); } // if Post::has($details), skip // otherwise, // 1- Post::store($details) (without image) // 2- Cache Image and Store in Image model, with post ID; } }