
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 display 1 day ago in comments in laravel view
- Laravel onclick function not working
- Get content from web URL in laravel
- Laravel get single row by id
- Run artisan command to generate key in laravel
- How to pass variable from controller to model in Laravel
- How to add active class to menu item in laravel
- How to display HTML tags In Laravel blade
- How to send email in laravel
- How to create pivot table in laravel using migration
- How to display pivot table column value in laravel
- How to get tomorrow and yesterday date in laravel
- Get products with number of orders in Laravel
- How to get CSRF token in laravel controller
- Skip first n record and display rest records in laravel view
- Print query in laravel
- Call to undefined method App\Models\User::follow()
- Route not defined in Laravel
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- How to add unique records in pivot columns of Laravel pivot table
- Get posts belongs to a specific user in Laravel
- How to get path from current URL in Laravel
- Laravel route redirect not working
- How to create laravel project using composer
- How to get last month records in Laravel