laraveleloquentlaravel-8laravel-seeding

How can I Seed a Image using Laravel Seeder and store it in the Database?


I Am trying to insert a image in the Database using seeder but its not responding properly. I have to insert a image in the database from the seeders for my view process.

the image should be first view there is no create condition you can assume only edit condition so by default there must be some data in the database to manipulate with.

DB::table('rivers')->insert([

            [
                'name' => 'abcd',
                'location' => json_encode([lat, long]),
                'location_photo' => file_get_contents('public/1.png'),
                'description' => 'Description',
             ],
 ]);

Tried this way!


Solution

  • You can use this:

    DB::table('rivers')->insert([
    
                [
                    'name' => 'abcd',
                    'location' => json_encode([lat, long]),
                    'location_photo' => 'images/1.png',
                    'description' => 'Description',
                 ],
     ]);
    

    With images/1.png the image will be stored in public/images folder.