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 126<br />

.<br />

I refer to them as the local and foreign keys but they are actually both foreign keys on the pivot<br />

table. Think of local as the key closest to the model in which the relationship is defined and the<br />

foreign as the furthest.<br />

.<br />

Our models’ $table property should match what’s specified in the migrations and seeders.<br />

The last step in creating our API is to create the client-facing controllers.<br />

Generating Controllers<br />

The API controllers are different from those you might typically see, in a Laravel 4 application. They<br />

don’t load views; rather they respond to the requested content type. They don’t typically cater for<br />

multiple request types within the same action. They are not concerned with interface; but rather<br />

translating and formatting model data.<br />

Creating them is a bit more tricky than the other classes we’ve done so far:<br />

1 php artisan generate:controller EventController<br />

The command isn’t much different, but the generated file is far from ready:<br />

1

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

Saved successfully!

Ooh no, something went wrong!