9951 explained code solutions for 126 technologies


php-fakerHow can I use Laravel Faker to generate boolean values?


You can use Laravel Faker to generate boolean values by using the boolean() method.

Example code

$booleanValue = Faker\Factory::create()->boolean();

Output example

true

The boolean() method generates a random boolean value of either true or false. It takes no parameters.

Code explanation

  • Faker\Factory::create() - creates a new Faker\Generator instance
  • boolean() - generates a random boolean value

Helpful links

Edit this code on GitHub