kuvia/app/Console/Commands/ImageToServer.php

51 lines
1.0 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\Image;
use Illuminate\Console\Command;
class ImageToServer extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'server:set-image';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Add to all Image with no server a new one';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$server = \App\Models\Server::query()->get();
#var_dump($server);exit();
$images = Image::query()->whereNull("servername")->get();
foreach($images as $image) {
$servername = $server[0]->servername;
$image->servername = $servername;
$image->saveOrFail();
}
}
}