Use Resource Controller, Artisan and Tinker to set up REST API in Laravel 5.3
In the last post we built the client side of our application with Vue.js and Google Maps API.
Before that, we generated our application and added authentication using Laravel 5.3.
In this post we will handle generating a model and controller for our application. This will set up a database table and handle RESTful routing. To save boilerplate code we’ll utilize Laravel’s Resource Controller. Lastly we’ll test that it works by adding data to our database and querying it using Eloquent and the php artisan tinker command.
The source code for this application is available here: https://github.com/connor11528/laravel-5.3-app
Generate the Model
For this one our model is going to be called Candidates with a name, email, phone, lat, long, street, city, state and zip. We head to the command line and run:
$ php artisan make:model Candidate
$ php artisan make:migration create_candidates_table
Then in the database/migrations we will find a create_candidates_table file with a number before it…