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.

API<br />

I seldom think of MVC in terms of applications which don’t really have views. Turns out Laravel 4<br />

is stocked with features which make REST API’s a breeze to create and maintain.<br />

.<br />

The code for this chapter can be found at: https://github.com/formativ/tutorial-laravel-4-api<br />

Dependencies<br />

One of the goals, of this tutorial, is to speed up our prototyping. To that end; we’ll be installing Jeffrey<br />

Way’s Laravel 4 Generators. This can be done by amending the composer.json file to including the<br />

following dependency:<br />

1 "way/generators" : "dev-master"<br />

.<br />

This was extracted from composer.json.<br />

We’ll also need to add the GeneratorsServiceProvider to our app config:<br />

1 "Way\Generators\GeneratorsServiceProvider"<br />

.<br />

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

You should now see the generate methods when you run artisan.<br />

Creating Resources With Artisan<br />

Artisan has a few tasks which are helpful in setting up resourceful API endpoints. New controllers<br />

can be created with the command:

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

Saved successfully!

Ooh no, something went wrong!