56 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Console\Commands;
 | 
						|
 | 
						|
use Illuminate\Console\Command;
 | 
						|
use App\Models\Regions;
 | 
						|
use App\Models\Seed;
 | 
						|
 | 
						|
class scraperAddSeed extends Command
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * The name and signature of the console command.
 | 
						|
     *
 | 
						|
     * @var string
 | 
						|
     */
 | 
						|
    protected $signature = 'scraper:add-seed';
 | 
						|
 | 
						|
    /**
 | 
						|
     * The console command description.
 | 
						|
     *
 | 
						|
     * @var string
 | 
						|
     */
 | 
						|
    protected $description = 'Add new seed to database.';
 | 
						|
 | 
						|
    /**
 | 
						|
     * Execute the console command.
 | 
						|
     */
 | 
						|
    public function handle()
 | 
						|
    {
 | 
						|
 | 
						|
        $regions = Regions::all()->pluck('name', 'id')->all();
 | 
						|
        
 | 
						|
 | 
						|
        $regionChoice = $this->choice(
 | 
						|
            'For which region do you want to add the seed?',
 | 
						|
            $regions
 | 
						|
        );
 | 
						|
 | 
						|
        $url = $this->ask('Please input the seed url');
 | 
						|
 | 
						|
        if(!str_contains($url, 'e-domizil.ch')){
 | 
						|
            $this->error('Given seed url is not valid.');
 | 
						|
        }else{
 | 
						|
 | 
						|
            $seed = Seed::create([
 | 
						|
                'uri' => $url,
 | 
						|
                'region_id' => array_search($regionChoice, $regions)
 | 
						|
            ]);
 | 
						|
 | 
						|
            $this->info('New Seed has been added: '.$seed);
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
    }
 | 
						|
}
 |