No description, website, or topics provided.
PHP ApacheConf
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
api/Users initial commit Apr 15, 2016
bootstrap initial commit Apr 12, 2016
config initial commit Apr 12, 2016
database initial commit Apr 15, 2016
infrastructure update dependencies Apr 15, 2016
public initial commit Apr 12, 2016
storage Ignore schedule files Mar 17, 2016
.env.example
.gitattributes Use vendors. Feb 12, 2015
.gitignore add to gitignore Feb 12, 2016
artisan Use the ::class notation Jun 8, 2015
composer.json update dependencies Apr 15, 2016
composer.lock update dependencies Apr 15, 2016
phpunit.xml misc bugs Apr 12, 2016
readme.md initial commit Apr 15, 2016
server.php Sync with 5.0 Jun 15, 2015

readme.md

A modern REST API in Laravel 5 Part 2: Resource controls

The article can be read here

Setup

composer install && php artisan migrate

Remember to create an .env file!!

Example commands

Use these commands in the terminal to test your api. Replace http://larapi-part-2.dev with the URL to your own local API.

Inserts a user into the database

curl -X POST -H 'Content-Type: application/json' -d '{"user": {"email": "user@user.com", "name": "A user", "password": "12345678"}}' http://larapi-part-2.dev/users

Inserts some roles into the database

curl -X POST -H 'Content-Type: application/json' -d '{"role": {"name": "Role #1"}}' http://larapi-part-2.dev/roles &&
curl -X POST -H 'Content-Type: application/json' -d '{"role": {"name": "Role #2"}}' http://larapi-part-2.dev/roles &&
curl -X POST -H 'Content-Type: application/json' -d '{"role": {"name": "Role #3"}}' http://larapi-part-2.dev/roles

Get roles

curl http://larapi-part-2.dev/roles

Get users and eager load their roles

curl --globoff http://larapi-part-2.dev/users?includes[]=roles

Attach role ID 1 & 2 to user ID 1 Note you may have to change the IDs to fit your own data

curl -X POST -H 'Content-Type: application/json' -d '{"roles": [1,2]}' http://larapi-part-2.dev/users/1/roles

Remove role ID 2 from the user ID 1 Note you may have to change the IDs to fit your own data

curl -X DELETE -H 'Content-Type: application/json' -d '{"roles": [2]}' http://larapi-part-2.dev/users/1/roles

Set the roles of user ID 1 to IDs 1,2 & 3 Note you may have to change the IDs to fit your own data

curl -X PUT -H 'Content-Type: application/json' -d '{"roles": [1,2,3]}' http://larapi-part-2.dev/users/1/roles

Get users and eager load roles in IDs mode

curl --globoff http://larapi-part-2.dev/users?includes[]=roles:ids

Get users and eager load roles in sideload mode

curl --globoff http://larapi-part-2.dev/users?includes[]=roles:sideload