LoginSignup
4
0

More than 1 year has passed since last update.

Laravel Faker->image() で画像が作成できない時の対処

Last updated at Posted at 2022-09-30

作成したFactoryクラス内で以下を実行しても画像が生成されませんでした。

$this->faker->image(storage_path('app/public/hoge'), 640, 480);

こちらに記載されている方法で解決しました。
https://stackoverflow.com/questions/72142021/images-dont-save-using-faker-image-in-seeder/73059602#73059602

私の開発環境では、ひとまず画像が生成されるようになったので、その時の方法を記載しておりますが、これがベストな対処かは分かり兼ねます。対応は自己責任でお願い致します。

vendor/fakerphp/faker/src/Faker/Provider/Image.php
・・・・・省略・・・・・
public const BASE_URL = 'https://placehold.jp'; // 変更
・・・・・省略・・・・・
curl_setopt($ch, CURLOPT_FILE, $fp); //この行の下に以下の2行を追加
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//追加
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//追加
・・・・・省略・・・・・
4
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0