Я получаю информацию об игре и изображения от IGDB Api с помощью жадности, а затем я храню изображения на своем диске и информацию в дБ.Он работает с файлом контроллера, но тот же код не работает с командным файлом ремесленника (не работает только Image Intervention).
GameController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Game;
use Image;
use Carbon\Carbon;
use GuzzleHttp\Client;
class GameController extends Controller
{
public function index()
{
$client = new Client(['headers' => ['user-key' => 'xxxxx']]);
$response = $client->request('GET', 'https://api-endpoint.igdb.com/games/96209');
$result = json_decode($response->getBody(), true);
$nameGame = $result[0]['name'];
$imageGame = $result[0]['artworks'][0]['cloudinary_id'];
$summaryGame = $result[0]['summary'];
$releaseGame = $result[0]['first_release_date'];
$releaseGameDate = Carbon::createFromTimestamp($releaseGame/1000)->toDateTimeString();
$postImage = 'https://images.igdb.com/igdb/image/upload/t_1080p/' . $imageGame . '.jpg';
$filename = $imageGame. '.jpg';
$height = Image::make($postImage)->height();
Image::make($postImage)
->resize(null, 1920, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save( public_path('/images/games/image/large/' . $filename ), 75)
->resize(null, 480, function ($constraint) {
$constraint->aspectRatio();
})->save( public_path('/images/games/image/medium/' . $filename ), 75)
->resize(null, 128, function ($constraint) {
$constraint->aspectRatio();
})->save( public_path('/images/games/image/small/' . $filename ) );
$addit = new Game;
$addit->name = $nameGame;
$addit->image = $filename;
$addit->summary = $summaryGame;
$addit->release_date = $releaseGameDate;
$addit->save();
}
}
И тот же код в addGames.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Game;
use Image;
use Carbon\Carbon;
use GuzzleHttp\Client;
class addGames extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:addGames';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This command adding games to db';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$client = new Client(['headers' => ['user-key' => 'xxxx']]);
$response = $client->request('GET', 'https://api-endpoint.igdb.com/games/96209');
$result = json_decode($response->getBody(), true);
$nameGame = $result[0]['name'];
$imageGame = $result[0]['artworks'][0]['cloudinary_id'];
$summaryGame = $result[0]['summary'];
$releaseGame = $result[0]['first_release_date'];
$releaseGameDate = Carbon::createFromTimestamp($releaseGame/1000)->toDateTimeString();
$postImage = 'https://images.igdb.com/igdb/image/upload/t_1080p/' . $imageGame . '.jpg';
$filename = $imageGame. '.jpg';
$height = Image::make($postImage)->height();
Image::make($postImage)
->resize(null, 1920, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save( public_path('/images/games/image/large/' . $filename ), 75)
->resize(null, 480, function ($constraint) {
$constraint->aspectRatio();
})->save( public_path('/images/games/image/medium/' . $filename ), 75)
->resize(null, 128, function ($constraint) {
$constraint->aspectRatio();
})->save( public_path('/images/games/image/small/' . $filename ) );
$addit = new Game;
$addit->name = $nameGame;
$addit->image = $filename;
$addit->summary = $summaryGame;
$addit->release_date = $releaseGameDate;
$addit->save();
}
}
Я попытался найти, почему тот же код не работает в командном файле ремесленника, яне смог найти никакой информации об этом, поэтому я подумал, что найду решение по stackoverflow.Заранее спасибо:)