03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

E-Commerce 241<br />

18 $price = $faker->randomFloat(2, 5, 100);<br />

19<br />

20 Product::create([<br />

21 "name" => $name,<br />

22 "stock" => $stock,<br />

23 "price" => $price,<br />

24 "category_id" => $category->id<br />

25 ]);<br />

26 }<br />

27 }<br />

28 }<br />

29 }<br />

.<br />

This file should be saved as app/database/seeds/ProductTableSeeder.php.<br />

Here, we use the randomNumber() and randomFloat() methods. What’s actually happening, when<br />

you request a property value, is that Faker invokes a method of the same name (on one of the<br />

providers). We can just as easily use the $faker->word() means the same as $faker->word. Some of<br />

the methods (such as the random*() methods we’ve used here) take arguments, so we provide them<br />

in the method form.<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!