VANA/VANA-php/app/Console/Commands/AddEndpoint.php

45 lines
919 B
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Endpoint;
class AddEndpoint extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:add-endpoint {uri} {settings}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Give settings the following way "key:value;key2:value2"';
/**
* Execute the console command.
*/
public function handle()
{
$settings = explode(';', $this->argument('settings'));
$settings_data = [];
foreach ($settings as $s) {
$s = explode(':', $s, 2);
$settings_data[$s[0]] = $s[1];
}
Endpoint::updateOrCreate(
['uri' => $this->argument('uri')],
['settings' => $settings_data]
);
}
}