/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(SourceFormRequest $request) { // Save the new source Source::create($request->all()); flash()->success('New source has been added!'); return redirect('sources'); }
/** * Execute the console command. * * @return mixed */ public function handle() { // get sources from the old Lebanese blogs $sources = @file_get_contents('http://lebaneseblogs.com/sources/' . getenv('PASS')); $sources = json_decode($sources); foreach ($sources as $key => $source) { $this->info('Adding Source [ ' . $source->blog_name . ' ]'); // map old columns to new columns $newSource = Source::create(['shorthand' => $source->blog_id, 'name' => $source->blog_name, 'description' => $source->blog_description, 'url' => $source->blog_url, 'author' => $source->blog_author, 'author_twitter' => $source->blog_author_twitter_username, 'rss_feed' => $source->blog_rss_feed, 'active' => $source->blog_RSSCrawl_active]); // channels $oldChannels = preg_split('#\\s*,\\s*#', $source->blog_tags); $newChannels = []; foreach ($oldChannels as $key => $oldChannel) { // If this channel exists, add it. if (Channel::where('shorthand', $oldChannel)->get()->count()) { $newChannels[] = Channel::where('shorthand', $oldChannel)->first()->id; } } // Now associate source with list of channels; $newSource->channels()->sync($newChannels); } $this->comment('Import complete: Total Sources Added: ' . count($sources)); }
/** * This is used to add NEW sources not already in our sources table * */ private function syncSources($post, $request) { if (!$request->has('source_list')) { $post->sources()->detach(); return; } $allSourceIds = array(); foreach ($request->source_list as $sourceId) { if (substr($sourceId, 0, 4) == 'new:') { $newSource = Source::create(['name' => substr($sourceId, 4)]); $allSourceIds[] = $newSource->id; continue; } $allSourceIds[] = $sourceId; } $post->sources()->sync($allSourceIds); }
/** * Create a new source. * * @param Request $request * @return Response */ public function source(Request $request) { $this->validate($request, ['name' => 'required|max:255']); Source::create(['name' => $request->name]); return redirect('/sources'); }
public function create($data) { return Source::create($data); }