ConsultancyProject1_Auslast.../scraper/app/Console/Commands/scraperAddSeed.php

56 lines
1.1 KiB
PHP
Raw Normal View History

2024-06-27 21:38:31 +02:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
2024-07-05 14:11:54 +02:00
use App\Models\Regions;
2024-06-27 21:38:31 +02:00
use App\Models\Seed;
2024-07-01 20:55:25 +02:00
class scraperAddSeed extends Command
2024-06-27 21:38:31 +02:00
{
/**
* The name and signature of the console command.
*
* @var string
*/
2024-07-05 14:11:54 +02:00
protected $signature = 'scraper:add-seed';
2024-06-27 21:38:31 +02:00
/**
* The console command description.
*
* @var string
*/
2024-07-01 20:55:25 +02:00
protected $description = 'Add new seed to database.';
2024-06-27 21:38:31 +02:00
/**
* Execute the console command.
*/
public function handle()
{
2024-07-05 14:11:54 +02:00
$regions = Regions::all()->pluck('name', 'id')->all();
2024-06-27 21:38:31 +02:00
2024-07-05 14:11:54 +02:00
$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);
}
2024-06-27 21:38:31 +02:00
}
}