Skip to content

About

Multi-role Laravel REST API with Passport OAuth2, role-based access control, and event-driven queued notifications.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

22 Commits

Folders and files

Repository files navigation

ServiceHub

ServiceHub is a multi-role REST API platform built with Laravel 12 that connects service vendors with customers. It provides a full vendor lifecycle β€” from registration and admin approval to service listing β€” backed by secure OAuth2 authentication, role-based access control, queued email notifications, and image management.


Table of Contents


Features

πŸ” Authentication & Authorization

  • User registration (customer) and vendor registration (with business profile)
  • OAuth2 token-based login via Laravel Passport (Password Grant)
  • Role-based access control via Spatie Laravel Permission (admin, vendor, customer)
  • Vendor login is blocked until the account is approved by an admin

πŸͺ Vendor Management (Admin)

  • List all vendors with pagination
  • View vendor details
  • Approve or reject vendor applications
  • Soft-delete vendors
  • Automated email notification sent to vendors on approval/rejection via a queued listener

πŸ› οΈ Service Management (Vendor)

  • Full CRUD for services (create, read, update, delete)
  • Each service belongs to a category and a vendor
  • Supports multiple image uploads per service (JPEG, PNG, WebP; max 2 MB each)
  • Services are uniquely named per vendor and auto-generate SEO-friendly slugs
  • Active / inactive status management

πŸ“‚ Service Categories (Admin)

  • Admins can create, update, and delete service categories
  • Vendors can view the category list to use when listing services
  • Slugified, with optional description and status toggle

πŸ“§ Event-Driven Email Notifications

  • VendorStatusUpdatedEvent fires when a vendor is approved or rejected
  • SendVendorStatusEmailListener handles the event and dispatches the appropriate queued email (VendorApprovedMail / VendorRejectedMail)

Tech Stack

Layer Technology
Framework Laravel 12
Language PHP 8.2+
Authentication Laravel Passport (OAuth2)
Authorization Spatie Laravel Permission
Database MySQL
Queue Database queue driver
Mail Configurable (SMTP / Mailgun / log)
Asset Bundling Vite + Tailwind CSS v4
Testing Pest PHP

Architecture & Roles

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Customer   β”‚       β”‚    Vendor    β”‚       β”‚    Admin     β”‚
β”‚  (register,  β”‚       β”‚  (register,  β”‚       β”‚  (manage     β”‚
β”‚    login)    β”‚       β”‚   login,     β”‚       β”‚  vendors &   β”‚
β”‚              β”‚       β”‚   services)  β”‚       β”‚  categories) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                     β”‚                      β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                    Laravel REST API (Passport)

Vendor Lifecycle

Register β†’ Pending β†’ Admin Reviews β†’ Approved βœ… / Rejected ❌
                                          β”‚               β”‚
                                     Email sent       Email sent
                                     (queued)         (queued)
                                          β”‚
                                   Can now login
                                   & list services

Database Schema

Table Key Columns
users id, name, email, password
vendors id, user_id (FK), business_name, logo, phone, address, city, status (0=pending, 1=approved, 2=rejected, 3=suspended), deleted_at
service_categories id, name, slug, description, status
services id, vendor_id (FK), category_id (FK), name, slug, short_description, description, price, status (0=inactive, 1=active), deleted_at
service_images id, service_id (FK), path, alt_text
oauth_* Passport OAuth2 tables
permissions / roles Spatie permission tables

API Endpoints

Public Routes

Method Endpoint Description
POST /api/register Register a new customer account
POST /api/vendor/register Register a new vendor (pending approval)
POST /api/login Login and receive an OAuth2 access token

Admin Routes β€” auth:api + role:admin

Method Endpoint Description
GET /api/users List all users
GET /api/vendors List all vendors (paginated)
GET /api/vendors/{id} Get a specific vendor
DELETE /api/vendors/{id} Soft-delete a vendor
PATCH /api/vendors/{id}/approve Approve a vendor
PATCH /api/vendors/{id}/reject Reject a vendor
POST /api/service-categories Create a service category
PUT/PATCH /api/service-categories/{id} Update a service category
DELETE /api/service-categories/{id} Delete a service category

Vendor Routes β€” auth:api + role:vendor

Method Endpoint Description
GET /api/services List all services for authenticated vendor
POST /api/services Create a new service with images
GET /api/services/{id} Get a specific service
PUT/PATCH /api/services/{id} Update a service
DELETE /api/services/{id} Delete a service

Shared Routes β€” auth:api + role:admin|vendor

Method Endpoint Description
GET /api/service-categories List all service categories

Getting Started

Prerequisites

  • PHP >= 8.2
  • Composer
  • Node.js >= 18 & npm
  • MySQL
  • A mail service (or use log driver for local development)

Installation

1. Clone the repository

git clone https://github.com/atanubarua/ServiceHub.git
cd ServiceHub

2. Install PHP dependencies

composer install

3. Set up environment

cp .env.example .env
php artisan key:generate

4. Configure your database in .env:

DB_DATABASE=servicehub
DB_USERNAME=your_db_user
DB_PASSWORD=your_db_password

5. Run migrations and seed roles

php artisan migrate
php artisan db:seed

6. Install Passport and create OAuth client

php artisan passport:install

Copy the generated Password Grant Client ID and Secret into your .env:

PASSPORT_CLIENT_ID=your_client_id
PASSPORT_CLIENT_SECRET=your_client_secret
PASSPORT_LOGIN_ENDPOINT=oauth/token

7. Install frontend dependencies

npm install

Environment Variables

Key variables to configure in .env:

Variable Description
APP_URL Base URL of your application
DB_* MySQL database credentials
QUEUE_CONNECTION Set to database (default) or redis
MAIL_MAILER Mail driver (smtp, mailgun, log)
MAIL_FROM_ADDRESS Sender email address
PASSPORT_CLIENT_ID OAuth2 Password Grant client ID
PASSPORT_CLIENT_SECRET OAuth2 Password Grant client secret
PASSPORT_LOGIN_ENDPOINT OAuth token endpoint (default: oauth/token)

Running the Project

One-command setup (installs, migrates, and builds everything)

composer setup

Start the development server (API + Queue + Vite)

composer dev

This runs three concurrent processes:

  • php artisan serve β€” Laravel dev server
  • php artisan queue:listen β€” processes queued emails
  • npm run dev β€” Vite asset bundler

Testing

composer test

Or directly:

php artisan test

Tests are written with Pest PHP.


Project Structure

app/
β”œβ”€β”€ Events/
β”‚   └── VendorStatusUpdatedEvent.php   # Fired on vendor approve/reject
β”œβ”€β”€ Http/
β”‚   └── Controllers/
β”‚       β”œβ”€β”€ Admin/
β”‚       β”‚   └── VendorController.php   # Admin vendor management
β”‚       β”œβ”€β”€ Vendor/
β”‚       β”‚   └── ServiceController.php  # Vendor service CRUD
β”‚       β”œβ”€β”€ AuthController.php         # Register & login
β”‚       └── ServiceCategoryController.php
β”œβ”€β”€ Listeners/
β”‚   └── SendVendorStatusEmailListener.php  # Sends queued emails
β”œβ”€β”€ Mail/
β”‚   β”œβ”€β”€ VendorApprovedMail.php
β”‚   └── VendorRejectedMail.php
└── Models/
    β”œβ”€β”€ User.php
    β”œβ”€β”€ Vendor.php
    β”œβ”€β”€ Service.php
    β”œβ”€β”€ ServiceCategory.php
    └── ServiceImage.php

database/
β”œβ”€β”€ migrations/        # All table schemas
└── seeders/
    β”œβ”€β”€ DatabaseSeeder.php
    └── RoleSeeder.php # Seeds admin, vendor, customer roles

routes/
└── api.php            # All API route definitions

License

This project is open-sourced software licensed under the MIT license.

About

Multi-role Laravel REST API with Passport OAuth2, role-based access control, and event-driven queued notifications.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages