InterviewSolution
Saved Bookmarks
| 1. |
What are seeders in Laravel? |
|
Answer» Seeders in Laravel are used to put data in the database tables AUTOMATICALLY. After running migrations to CREATE the tables, we can run `php artisan db:seed` to run the seeder to populate the database tables. We can create a new Seeder using the below artisan COMMAND: php artisan make:seeder [className] It will create a new Seeder like below: <?phpuse App\Models\Auth\User;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Seeder;class UserTableSeeder extends Seeder{ /** * Run the database seeds. */ public function run() { factory(User::class, 10)->create(); }}The run() method in the above CODE snippet will create 10 new users using the User factory. Factories will be explained in the next question. |
|