Global Faker Helper Function Example in Laravel 9.x

We always use fake data when we create our software. In laravel we use faker to generate fake data. But this faker can be used only in seeder or factory class or in our controller if we used it.

But This PR by Tim MacDonald adds a global fake() helper to create fake data in Laravel 9.x application. Now we can use this fake() function in the entire application. Even in our blade file also.

See the below example of fake() helper: Assume we are in blade components:

 

To insert value:

DB::table('users')->insert(['name' => fake()->unique()->name()]);

 

Read also: How to Create Dynamic Nav Bar From Database in Laravel?

 

Hope it can help you.

 

Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js