A simple laravel API example to show CRUD operations
git clone https://github.com/kaikezhang/ApiExample.git ApiExample
cd ApiExample
composer install
cp .env.example .env
php artisan key:generate
- Create a database and inform .env
php artisan migrate
to create tablesphp artisan serve
to start the app on http://localhost:8000/ or config a web server to start the app
laravel new ApiExample
- create database and inform .env
php artisan make:model Task --migration
- Edit migration file
php artisan migrate
Edit routes/api.php
- Details can be found at this commit
-
Create a task
Post
$domain/api/tasks
insert aname
field in body. -
Show all tasks
Get
$domain/api/tasks
-
Delete a task
Delete
$domain/api/tasks/{id}
-
Update a task
Put
$domain/api/tasks/{id}
insertname
field in body and selectx-www-form-urlencoded
.