【问题标题】:Images from PHPFaker got deleted when stored in storage/app/public/news folder来自 PHPFaker 的图像在存储在 storage/app/public/news 文件夹中时被删除
【发布时间】:2021-07-28 15:11:04
【问题描述】:

我有两张桌子newsimages。这两个表具有一对多的关系(一个是新闻)。我正在尝试在图像上创建工厂,但在我使用种子迁移后,图像保存到新闻目录但一秒钟后它被删除,并且数据库上的路径返回news。我读过这个question 但是 laravel 8.4(我当前的 laravel 项目)使用 phpfaker,所以我猜它现在已经被弃用了。

ImageFactory.php 文件

<?php

namespace Database\Factories;

use App\Models\Image;
use Illuminate\Database\Eloquent\Factories\Factory;

class ImageFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Image::class;

    /**
     * State dari gambarnya, 
     * pilih satu [news, packages, destinations]
     */
    public function news()
    {
        return $this->state(function (array $attributes) {
            return [
                'role' => 'news',
            ];
        });
    }
    public function packages()
    {
        return $this->state(function (array $attributes) {
            return [
                'role' => 'packages',
            ];
        });
    }
    public function destinations()
    {
        return $this->state(function (array $attributes) {
            return [
                'role' => 'destinations',
            ];
        });
    }

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'path' => 'news' . '/' . $this->faker->image(storage_path('app/public/news'), 2000, 1500, null, false),
        ];
    }
}

storage/app/publicstorage/app/public/news 具有 .gitignore 文件。我不知道这是否相关,因为我的同事迁移种子没有任何问题。

【问题讨论】:

    标签: php laravel faker


    【解决方案1】:

    参考this comment,你只需要去供应商PHPFaker上的Images.php文件并添加这些代码

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    

    $success = curl_exec($ch) &amp;&amp; curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200; 之前

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-05
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      • 2016-08-19
      相关资源
      最近更新 更多