如何使用Laravel的Faker在存储中生成和下载图像?
如何使用Laravel的Faker在存储中生成和下载图像?
我希望在运行播种机下载图像并自动保存在存储/类别文件夹中,但是在运行播种机时,将图像全部下载一秒钟,然后消失或删除,因此我不知道发生了什么。
这是类别的
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class CategoryFactory extends Factory
{
public function definition()
{
return [
'image' => 'categories/' . $this->faker->image(storage_path('app' . DIRECTORY_SEPARATOR . 'public/categories'),640, 480, null, false)
];
}
}
how to generate and download images in storage using laravel's faker?
I want when running seeders to download images and save them automatically in the storage/categories folder, but when running seeder the images are downloaded all for a second and then they disappear or are deleted, so I don't know what is happening.
this is CategoryFactory
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class CategoryFactory extends Factory
{
public function definition()
{
return [
'image' => 'categories/' . $this->faker->image(storage_path('app' . DIRECTORY_SEPARATOR . 'public/categories'),640, 480, null, false)
];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
存储:: makedirectory('categories')
如果将驱动程序设置为public
,则将在storege/app/code中创建一个目录。因此,使用
faker-&gt; image()
路径需要为storage_path('app/dummy')
时,路径需要使用。Storage::makeDirectory('categories')
will create a directory atstorage/app/categories
if the driver is set topublic
. So when using withfaker->image()
the path needs to bestorage_path('app/dummy')
.