Posts API, built with Laravel 9
& Laravel Sanctum
.
I would appreciate it if you consider giving me a star for this repo ⭐
Field name | Type |
---|---|
id | bigint |
title | string |
slug | string |
excerpt | text |
body | text |
cover | text |
status | string |
meta_title | string |
meta_description | text |
meta_keywords | text |
published_at | datetime |
created_at | datetime |
updated_at | datetime |
Field name | Type |
---|---|
id | bigint |
name | string |
slug | string |
parent_id | bigint |
Field name | Type |
---|---|
id | bigint |
name | string |
slug | string |
Field name | Type |
---|---|
id | bigint |
name | string |
phone | string |
string | |
ip | ip |
user_agent | text |
status | boolean |
body | text |
created_at | datetime |
updated_at | datetime |
- A post belongs to many categories
- A post belongs to many tags
- A post have many comments
- A category belongs to many posts
- A category have one parent
- A category have zero or many child
- A tag belongs to many posts
- A comment belong to one post
- PHP >= 8.1
- Laravel 9
- PostgreSQL (or any supported DBMS)
- Clone the repository
git clone https://github.com/omaghd/oposts-api-laravel-sanctum.git oposts
- Change directory to the project
cd oposts
- Install the dependencies
composer install
- Copy .env file
cp .env.example .env
- Generate new application key
php artisan key:generate
- After creating a database (e.g. posts_api), change database info in .env file
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=posts_api
DB_USERNAME=postgres
DB_PASSWORD=password
- Migrate & Seed the database
php artisan migrate:fresh --seed
- Run the application
php artisan serve
After the database seeding, the default user credentials are:
Email: user@user
Password: password
If you use Postman, you can import this ready collection, I made it for you for free ;)
You can send the HTTP requests to the public endpoints to get responses.
After generating a token, you need to copy the generated token and send it for authorization as a Bearer token in the request header.
POST api/v1/auth .................................................... AuthController@auth
GET|HEAD api/v1/posts .................................... posts.index › PostController@index
GET|HEAD api/v1/posts/{post} ............................... posts.show › PostController@show
GET|HEAD api/v1/post/{id}/categories ......................... PostCategoriesController@index
GET|HEAD api/v1/post/{id}/tags ..................................... PostTagsController@index
GET|HEAD api/v1/post/{id}/comments ................................... PostCommentsController
GET|HEAD api/v1/post/{id}/comments?not_approved=1 .................... PostCommentsController
GET|HEAD api/v1/comments ........................... comments.index › CommentController@index
GET|HEAD api/v1/comments?not_approved=1 ............ comments.index › CommentController@index
POST api/v1/comments ........................... comments.store › CommentController@store
GET|HEAD api/v1/comments/{comment} ................... comments.show › CommentController@show
GET|HEAD api/v1/tags ....................................... tags.index › TagController@index
GET|HEAD api/v1/tags/{tag} ................................... tags.show › TagController@show
GET|HEAD api/v1/tag/{id}/posts ..................................... TagPostsController@index
POST api/v1/logout ................................................ AuthController@logout
POST api/v1/posts .................................... posts.store › PostController@store
PUT|PATCH api/v1/posts/{post} ........................... posts.update › PostController@update
DELETE api/v1/posts/{post} ......................... posts.destroy › PostController@destroy
GET|HEAD api/v1/trashed/posts ..................................... PostController@getTrashed
PATCH api/v1/restore/post/{id} .................................... PostController@restore
PATCH api/v1/post/{postId}/category/{categoryId} ......... PostCategoriesController@attach
DELETE api/v1/post/{postId}/category/{categoryId} ......... PostCategoriesController@detach
PATCH api/v1/post/{postId}/tag/{tagId} ......................... PostTagsController@attach
DELETE api/v1/post/{postId}/tag/{tagId} ......................... PostTagsController@detach
DELETE api/v1/comments/{id} ..................................... CommentController@destroy
PATCH api/v1/comments/{id}/approve ............................. CommentController@approve
PATCH api/v1/comments/{id}/disapprove ....................... CommentController@disapprove
POST api/v1/tags ....................................... tags.store › TagController@store
PUT|PATCH api/v1/tags/{tag} ............................... tags.update › TagController@update
DELETE api/v1/tags/{tag} ............................. tags.destroy › TagController@destroy
PATCH api/v1/tag/{tagId}/post/{postId} ......................... TagPostsController@attach
DELETE api/v1/tag/{tagId}/post/{postId} ......................... TagPostsController@detach
Website | omaghd.com |
---|---|
/in/omaghd | |
/omaghd | |
GitHub | /omaghd |
This project is MIT licensed.
Kindly give me a credit if you're going to use this project somewhere ❤️