Laravel 图像干预在 artisan 命令中不起作用

Laravel Image Intervention not working in artisan command

我正在使用 guzzle 从 IGDB Api 获取游戏信息和图像,然后我将图像存储在我的磁盘中,并将信息存储在数据库中。它在控制器文件上工作,但相同的代码在 artisan 命令文件上不起作用(只有图像干预不起作用)。

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


    }
}

我试图搜索为什么相同的代码在 artisan 命令文件中不起作用,我找不到任何相关信息,所以我想我会在 Whosebug 上找到解决方案。提前致谢:)

我解决了,感谢@niklaz 的日志建议 :) 当我使用 运行 artisan 命令时,我确实看到 public_path 出错了,我确实在 [中注册了 public 路径=12=] 现在好了:)