This API is a simple blog backend built with Laravel 12. It exposes RESTful endpoints for posts, categories, tags and comments and uses Laravel Sanctum for authentication.
- Install Composer dependencies:
composer install
- Copy
.env.exampleto.envand update your database configuration. - Run migrations:
php artisan migrate
- Serve the application:
php artisan serve
POST /api/register– Register a new user. The request must includename,email,password,password_confirmation, and arole(admin,editor,author, orreader). The response returns an API token and the created user including the selected role. If no role is provided the request will fail.POST /api/login– Get an authentication token.POST /api/logout– Revoke the current token.
The available user roles are admin, editor, author, and reader.
Seed data defaults to reader, but registration now requires clients to
explicitly choose a role.
GET /api/posts– List posts (searchable and paginated).POST /api/posts– Create a post (auth required).GET /api/posts/{post}– Show a single post.PUT /api/posts/{post}– Update a post (owner only).DELETE /api/posts/{post}– Delete a post (owner only).POST /api/posts/{post}/comments– Comment on a post.
All responses are JSON.