This is a Laravel-based API project that includes user authentication using ACL and Policies.
you can chck more information in - https://medium.com/@murilolivorato/getting-started-with-laravel-policies-how-to-control-access-a-step-by-step-guide-3bb080fe3762
-
Clone the repository:
git clone https://github.com/your-username/your-repo.git cd your-repo
-
Install dependencies:
composer install npm install
-
Copy the
.env.example
file to.env
and configure your environment variables:cp .env.example .env
-
Run the database migrations:
php artisan migrate
-
Seed the database :
php artisan db:seed
-
Login
POST /login
Request body:
{ "email": "[email protected]", "password": "password" }
-
Logout
POST /logout
Headers:
Authorization: Bearer {token}
-
Get Users
GET /users
Headers:
Authorization: Bearer {token}
-
Get User
GET /users/{user_id}
Headers:
Authorization: Bearer {token}
-
Create User
POST /users
Headers:
Authorization: Bearer {token} Content-Type: application/json
Request body:
{ "name": "New User", "email": "[email protected]", "password": "password" }
-
Update User
PUT /users/{user_id}
Headers:
Authorization: Bearer {token} Content-Type: application/json
Request body:
{ "name": "Updated User", "email": "[email protected]" }
-
Delete User
DELETE /users/{user_id}
Headers:
Authorization: Bearer {token}
-
Get Posts
GET /posts
Headers:
Authorization: Bearer {token}
-
Get Post
GET /posts/{post_id}
Headers:
Authorization: Bearer {token}
-
Create Post
POST /posts
Headers:
Authorization: Bearer {token} Content-Type: application/json
Request body:
{ "title": "New Post", "content": "Post content" }
-
Update Post
PUT /posts/{post_id}
Headers:
Authorization: Bearer {token} Content-Type: application/json
Request body:
{ "title": "Updated Post", "content": "Updated content" }
-
Delete Post
DELETE /posts/{post_id}
Headers:
Authorization: Bearer {token}
{
"info": {
"_postman_id": "b9adee5b-c58e-4603-a994-3cacc3f80f86",
"name": "Laravel Policies",
"description": "API collection for User and Post routes",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "9356399"
},
"item": [
{
"name": "Auth",
"item": [
{
"name": "Login",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"[email protected]\",\n \"password\": \"password\"\n}"
},
"url": {
"raw": "{{base_url}}/api/login",
"host": [
"{{base_url}}"
],
"path": [
"api",
"login"
]
}
},
"response": []
},
{
"name": "Logout",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{token}}"
}
],
"url": {
"raw": "{{base_url}}/api/logout",
"host": [
"{{base_url}}"
],
"path": [
"api",
"logout"
]
}
},
"response": []
}
]
},
{
"name": "Users",
"item": [
{
"name": "Get Users",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"url": {
"raw": "{{base_url}}/api/users",
"host": [
"{{base_url}}"
],
"path": [
"api",
"users"
]
}
},
"response": []
},
{
"name": "Get User",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"url": {
"raw": "{{base_url}}/api/users/1",
"host": [
"{{base_url}}"
],
"path": [
"api",
"users",
"1"
]
}
},
"response": []
},
{
"name": "Create User",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"New User\",\n \"email\": \"[email protected]\",\n \"password\": \"password\"\n}"
},
"url": {
"raw": "{{base_url}}/api/users",
"host": [
"{{base_url}}"
],
"path": [
"api",
"users"
]
}
},
"response": []
},
{
"name": "Update User",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"Updated User\",\n \"email\": \"[email protected]\"\n}"
},
"url": {
"raw": "{{base_url}}/api/users/41",
"host": [
"{{base_url}}"
],
"path": [
"api",
"users",
"41"
]
}
},
"response": []
},
{
"name": "Delete User",
"request": {
"method": "DELETE",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"url": {
"raw": "{{base_url}}/api/users/41",
"host": [
"{{base_url}}"
],
"path": [
"api",
"users",
"41"
]
}
},
"response": []
}
]
},
{
"name": "Posts",
"item": [
{
"name": "Get Posts",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"url": {
"raw": "{{base_url}}/api/posts",
"host": [
"{{base_url}}"
],
"path": [
"api",
"posts"
]
}
},
"response": []
},
{
"name": "Get Post",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"url": {
"raw": "{{base_url}}/api/posts/34",
"host": [
"{{base_url}}"
],
"path": [
"api",
"posts",
"34"
]
}
},
"response": []
},
{
"name": "Create Post",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"New Post\",\n \"content\": \"Post content\"\n}"
},
"url": {
"raw": "{{base_url}}/api/posts",
"host": [
"{{base_url}}"
],
"path": [
"api",
"posts"
]
}
},
"response": []
},
{
"name": "Update Post",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"Updated Post\",\n \"content\": \"Updated content\"\n}"
},
"url": {
"raw": "{{base_url}}/api/posts/33",
"host": [
"{{base_url}}"
],
"path": [
"api",
"posts",
"33"
]
}
},
"response": []
},
{
"name": "Delete Post",
"request": {
"method": "DELETE",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"url": {
"raw": "{{base_url}}/api/posts/33",
"host": [
"{{base_url}}"
],
"path": [
"api",
"posts",
"33"
]
}
},
"response": []
}
]
}
],
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "2|QNoLbgptc0r4SMCzvRdtG1glGXl31wcg8Abwddo8dfc858a8",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
}
],
"variable": [
{
"key": "base_url",
"value": "localhost:8081",
"type": "string"
}
]
}