schepotin / laravel-api
Laravel API
Installs: 750
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 5
Forks: 3
Open Issues: 1
Language:Vue
Requires
- php: >=7.0
- illuminate/console: ~5
- illuminate/support: ~5
- nikic/php-parser: ^3.0|^4.0
README
Laravel API
Install
Install package:
composer require schepotin/laravel-api
Run command:
php artisan laravel-api:publish --api
Run migrations:
php artisan migrate
Boilerplate for Vue
php artisan laravel-api:publish --vue
npm install
npm run dev
Eslint
npm run eslint
API
Register:
request:
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); });
response:
{ "status": 1, "token": "yQZKTMgpB9wmX3seCH1XKrHyq62YQXijvnoAkFsHXmNcuv5SRhiTuWqbdsIP" }
Login:
request:
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); });
response:
{ "status": 1, "token": "yQZKTMgpB9wmX3seCH1XKrHyq62YQXijvnoAkFsHXmNcuv5SRhiTuWqbdsIP" }
Password reset:
request:
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); });
response:
{ "status": 1, "data": { "message": "passwords.sent" } }
request:
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); });
response:
{ "status": 1, "data": { "message": "passwords.reset" } }
Get current logged user
request:
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); });
response:
{ "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" } }