public function run() { foreach (range(1, 5) as $idx) { $name = ucwords($this->faker->sentence(2)); $id = ''; foreach (explode(' ', $name) as $word) { $id .= $word[0]; } $data = ['id' => $id, 'name' => $name]; Subject::create($data); } }
public function scrape($job, $data) { $url = sprintf(self::CATALOG_URL . self::QUERY_PARAMS, $data['campus'] ?: 'corvallis', $data['term'] ?: ''); $contents = file_get_contents($url); Model::unguard(); array_map(function ($subj) { try { if (is_null(Subject::find($subj)->first())) { $subj = Subject::create($subj); print_r($subj->toArray()); } \Queue::push('Courses\\Jobs\\Scraper\\ScrapeSubject', ['subject' => $subj['id']]); } catch (Illuminate\Database\QueryException $e) { } }, $this->getSubjects($contents)); $job->delete(); }