
Create project factory and seed data in laravel
Created at 22-Jul-2021 ,
By samar
Create project factory and seed data in laravel
In this article, we will see how to solve "Create project factory and seed data in laravel".
You can create the factory to generate the fake data and after that create a project seeder class and run that seeder class to seed dummy data in laravel-
Create factory for project table
php artisan make:factory ProjectFactory //database\factories\ProjectFactory.php public function definition() { return [ 'name' => $this->faker->word, ]; }
-
Create dummy records for project table using seeder
php artisan make:seeder ProjectSeeder //Import Project class use App\Models\Project; public function run() { $project = Project::factory()->count(5)->create(); } php artisan db:seed --class=ProjectSeeder
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- How to delete record in Laravel with ajax
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- How to get tomorrow and yesterday date in laravel
- Method Illuminate\Http\Request::validated does not exist
- How to pass link from controller to view in laravel on ajax call
- How to add columns in existing table using migration in laravel
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Pass value from controller to model in laravel
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- Route prefix with auth middleware in laravel
- Return view from route Laravel
- How to check record exist or not in relationship table
- Get laravel version
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- Cannot end a section without first starting one
- In order to use the Auth::routes() method, please install the laravel/ui package
- How to get selected categories on edit record with Select2
- Class 'App\Providers\Auth' not found
- Validation for multiple forms on same page in laravel
- Recursive function example code PHP Laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- How to get images from AWS s3 and display in Laravel blade
- How to check duplicate entry in laravel
- Laravel 5.4 save data to database