47 lines
840 B
PHP
47 lines
840 B
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
use Log;
|
|
use App\Models\Game;
|
|
|
|
class Query extends Command
|
|
{
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'query {keyword}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Query the database';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$keyword = $this->argument('keyword');
|
|
if (is_numeric($keyword)) {
|
|
$game = Game::where('id', $keyword)->first();
|
|
if ($game) {
|
|
$game->printDetailed();
|
|
return;
|
|
}
|
|
}
|
|
$games = Game::where('title', 'LIKE', "%$keyword%")->get();
|
|
foreach ($games as $game) {
|
|
$game->printShort();
|
|
}
|
|
}
|
|
}
|