03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

E-Commerce 245<br />

.<br />

This file should be saved as app/controllers/ProductController.php.<br />

The CategoryController has a single index() method which returns all categories, and the<br />

ProductController has a single index() method which returns all the products. If ?category=n is<br />

provided to the product/index route, the products will be filtered by that category.<br />

We do, of course, still need to add these routes:<br />

1 Route::any("category/index", [<br />

2 "as" => "category/index",<br />

3 "uses" => "CategoryController@indexAction"<br />

4 ]);<br />

5<br />

6 Route::any("product/index", [<br />

7 "as" => "product/index",<br />

8 "uses" => "ProductController@indexAction"<br />

9 ]);<br />

.<br />

This was extracted from app/routes.php.<br />

Managing Accounts<br />

For users to be able to buy products, they will need to log in. We’ve added some users to the database,<br />

via the UserTableSeeder class, but we should create an authentication endpoint:<br />

1

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

Saved successfully!

Ooh no, something went wrong!