0

how can we make custom seeder in Laravel which can read the folder name and put into a specific column in database and the sub folder's name in the next column and finally the file name in the last?

2 Answers2

1

Create seeder by artisan command for Users table below command run

php artisan make:seeder UsersTableSeeder

Now in database folder find UserTableSeeder.php in this

<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('users')->insert([
            'name' => str_random(10),
            'email' => str_random(10).'@gmail.com',
            'password' => bcrypt('secret'),
        ]);
    }
}

in this str_random for random string generate Now, run this seeder by below command

php artisan db:seed
Nileshsinh Rathod
  • 948
  • 1
  • 17
  • 37
  • thanks but i knew this. i am building an application where a huge data is to be seeded into the database where the names of the main folders are the cities and the sub folders are the companies and files are the office locations. So i need a seeder which can read the name of the main folders are put it the cites column in the database and so on. – Zille Muhammad Jafary Jul 04 '17 at 17:19
0

check the documentation here https://laravel.com/docs/5.4/seeding#writing-seeders.

Vishal Varshney
  • 905
  • 6
  • 11