How to quickly generate data using faker and tinker in laravel


Posted 2 weeks ago | by Ryan Dhungel | on Laravel  | Viewed 69 times

You can generate fake data for any model and any fields you want in less than a minute using the existing tools that are available in laravel. They are factory and tinker.

This is a great way of working with laravel during development. This is how you can do it.

Step 1.


Go to database/factories/ModelFactories.php

 

$factory->define(App\Note::class, function (Faker\Generator $faker) {
static $password;

return [
'user_id' => 1,
'title' => $faker->sentence(10),
'body' => $faker->sentence(30),
];
});

Step 2.


In terminal run php artisan tinker then..

factory(App\Note::class, 10)->create();

You just created 10 instance of notes with title (10 sentences) and body (30 sentences). Happy Coding!



Specials


Build Laravel React CRUD/SPA APP in 2 hours
Build Laravel React CRUD/SPA APP in 2 hours

Build Laravel React CRUD/SPA APP in 2 hours

COUPON CODE: REACTCRUD with 90% off


Laravel with React JS - Build Twitter Like Real Ti...
Laravel with React JS - Build Twitter Like Real Time Web App

Laravel with React JS - Build Twitter Like Real Time Web App

COUPON CODE: LARAVELREACT with 90% off


Learn Laravel Building Multi User Blogging Platfor...
Learn Laravel Building Multi User Blogging Platform with SEO


React Redux Firebase CRUD App with Authentication
React Redux Firebase CRUD App with Authentication

React Redux Firebase CRUD App with Authentication

COUPON CODE: RRFTEN with 86% off


Become a Master of JavaScript from Scratch in 2018
Become a Master of JavaScript from Scratch in 2018

Become a Master of JavaScript from Scratch in 2018

COUPON CODE: JSMASTERSALE with 92% off


REACT - Up and Running with React ES6 and Open Sou...
REACT - Up and Running with React ES6 and Open Source API


Sublime Text for Rapid Web Development
Sublime Text for Rapid Web Development

Sublime Text for Rapid Web Development

COUPON CODE: LEARNSUBLIME with 90% off