This project is a backend RESTful API built with Laravel that supports blog management with Supabase file uploads, JWT-based authentication, role-based access control, and modular route structure. It's designed to be connected with any frontend (e.g., React, SvelteKit, Vue, Angular) or mobile platform.
- 📝 Blog CRUD with local or cloud (Supabase) image upload.
- 🔐 Authentication via JWT (JSON Web Tokens).
- 👥 Role-based access control (Admin / User).
- Admins can create, update, and delete blogs.
- Users can comment on blogs.
- 🧪 Full-featured test suite.
- ☁️ Optional Supabase file handling.
- 📁 Clean route structure:
/auth/blogs/comments/tags
The system has been tested using Laravel's built-in testing framework. Tests include:
- Blog creation (with and without Supabase).
- Auth flow (login, registration).
- Role restriction validation.
- Comment functionality.
To run tests:
php artisan testBesides the default Laravel .env configuration, the following environment variables are required for Supabase integration:
SUPABASE_URL=
SUPABASE_API_KEY=
SUPABASE_BUCKET=There are two ways to store blog images:
- Stores images in a Supabase bucket.
- Saves image URL and Supabase path to the database.
- Stores images in the local filesystem (
public/storage). - To use local storage:
- Comment out the Supabase-related code in the
storeanddestroyblog methods. - Remove Supabase columns from the migration files (
image_path_supabase,image_path_supabase_url). - Run migration refresh if needed.
- Comment out the Supabase-related code in the
Note: Choose one method based on your deployment preferences.
- Users must log in to access protected routes.
- Authentication is handled using JWT tokens.
- Role system:
- Admins: full blog CRUD access.
- Regular users: can only comment on blog posts.
- Laravel 12
- MySQL
- JWT (Laravel Sanctum / tymon/jwt-auth)
- Supabase (optional for cloud file storage)
- PHPUnit (testing)
Routes are organized for maintainability:
routes/
├── api.php
├── auth.php
├── blogs.php
├── tags.php
└── comments.php
git clone https://github.com/appletonmind/laravel-supabase-blog-api-with-jwt-role-auth.git
cd laravel-supabase-blog-api-with-jwt-role-auth
composer install
cp .env.example .env
php artisan key:generate
php artisan migrateAdd Supabase variables if using cloud upload.
This project is not open source. You may not use, modify, or distribute this code without prior written consent from the author.
See LICENSE for details.
If you'd like to request permission to use this code, please reach out via email: your-email@example.com.