Best laravel framework open-source packages.

Laravel api practice

Create CRUD REST API with Laravel API Resource https://medium.com/@kitloong/create-crud-rest-api-with-laravel-api-resource-3146d91b38b6
Updated 4 months ago

Article

https://medium.com/@kitloong/create-crud-rest-api-with-laravel-api-resource-3146d91b38b6

Setup

This project uses Sail.

Please install Docker in order to start using Sail.

Install project dependencies:

composer install

Setup env:

cp .env.example .env
php artisan key:generate

Startup services:

./vendor/bin/sail up -d # Up on port 8080

PS: .env has been pre-configured to support MySQL and Redis from sail.

Check service status:

curl http://localhost:8080/api/health

Migrate and seed database:

./vendor/bin/sail artisan migrate
./vendor/bin/sail artisan db:seed

Swagger

Generate swagger page

./vendor/bin/sail artisan l5-swagger:generate

Open http://localhost:8080/api/documentation with your favourite browser to browse Swagger page.

API example

List

Route: users.index

curl http://localhost:8080/api/users \
     -H 'Accept: application/json'

Get

Route: users.show

curl http://localhost:8080/api/users/1 \
     -H 'Accept: application/json'

Create

Route: users.store

curl -X POST http://localhost:8080/api/users \
     -H 'Accept: application/json' \
     -H 'Content-Type: application/json' \
     -d $'{
         "name": "Name",
         "email": "test@email.com",
         "password": "password"
      }'

Update

Route: users.update

curl -X PUT http://localhost:8080/api/users/1 \
     -H 'Accept: application/json' \
     -H 'Content-Type: application/json' \
     -d $'{
         "name": "Name",
         "email": "test@email.com"
      }'

Delete

Route: users.destroy

curl -X DELETE http://localhost:8080/api/users/7 \
     -H 'Accept: application/json'