I need to create 5 record in database. I have name, price and path column. I want to add image for column path in database, which should contains name of image NOT whole path using just factory and seeds from Laravel.
//PostFactory.php
use App\Post;
use Faker\Generator as Faker;
$factory->define(Post::class, function (Faker $faker) {
$filePath = public_path('images');
return [
'name' => $faker->name,
'price' => $faker->numberBetween($min = 100, $max = 900),
'path' => $faker->image($filePath,400,300),
];
});
//PostTableSeeder.php
use Illuminate\Database\Seeder;
class PostTableSeeder extends Seeder
{
public function run()
{
factory(App\Post::class, 5)->create();
}
}
I expect to add just name of image, instead of that I only have whole path in database.
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/30JwKSA
via IFTTT
Aucun commentaire:
Enregistrer un commentaire