schepotin / laravel-api
此包已被弃用且不再维护。未建议替换包。
Laravel API
v5.7.0
2018-09-29 11:02 UTC
Requires
- php: >=7.0
- illuminate/console: ~5
- illuminate/support: ~5
- nikic/php-parser: ^3.0|^4.0
README
Laravel API
安装
安装包
composer require schepotin/laravel-api
运行命令
php artisan laravel-api:publish --api
运行迁移
php artisan migrate
Vue 模板
php artisan laravel-api:publish --vue
npm install
npm run dev
Eslint
npm run eslint
API
注册
请求
fetch('/api/v1/register', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', }, body: "name=John&email=johndoe@gmail.com&password=qwerty&password_confirmation=qwerty", }) .then((response) => response.json()) .then((data) => { console.log(data); });
响应
{
"status": 1,
"token": "yQZKTMgpB9wmX3seCH1XKrHyq62YQXijvnoAkFsHXmNcuv5SRhiTuWqbdsIP"
}
登录
请求
fetch('/api/v1/login', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', }, body: "email=johndoe@gmail.com&password=123456", }) .then((response) => response.json()) .then((data) => { console.log(data); });
响应
{
"status": 1,
"token": "yQZKTMgpB9wmX3seCH1XKrHyq62YQXijvnoAkFsHXmNcuv5SRhiTuWqbdsIP"
}
密码重置
请求
fetch('/api/v1/password/email', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', }, body: "email=johndoe@gmail.com", }) .then((response) => response.json()) .then((data) => { console.log(data); });
响应
{
"status": 1,
"data": {
"message": "passwords.sent"
}
}
请求
fetch('/api/v1/reset/password', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', }, body: "email=johndoe@gmail.com&password=qwerty&password_confirmation=qwerty&token=2b8db1c9655ed1dcf1752867b652774e48e890e2709daa992f271df5d787a8ce", }) .then((response) => response.json()) .then((data) => { console.log(data); });
响应
{
"status": 1,
"data": {
"message": "passwords.reset"
}
}
获取当前登录用户
请求
fetch('/api/v1/user/current', { method: 'GET', headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', Authorization: 'Bearer yQZKTMgpB9wmX3seCH1XKrHyq62YQXijvnoAkFsHXmNcuv5SRhiTuWqbdsIP', }, }) .then((response) => response.json()) .then((data) => { console.log(data); });
响应
{
"status": 1,
"data": {
"id": 1,
"name": "John",
"email": "johndoe@gmail.com",
"created_at": "2017-09-23 12:26:44",
"updated_at": "2017-09-23 12:26:44"
}
}