Archived
1
0
Fork 0
This repository has been archived on 2021-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
ifnews/app/Commands/Query.php
2020-05-03 00:52:40 +07:00

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();
}
}
}