PHPackages                             dwivedianuj9118/laravel-api-starter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. dwivedianuj9118/laravel-api-starter

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

dwivedianuj9118/laravel-api-starter
===================================

A complete API Starter Kit for Laravel 11+ designed to accelerate backend development. This package provides a clean and scalable API architecture with authentication, request validation, standardized API responses, error handling, and best practices. Perfect for SaaS platforms, mobile apps, admin panels, and high-performance REST APIs built with Laravel.

1.0.2(3mo ago)011MITPHPPHP ^8.2

Since Jan 28Pushed 3mo agoCompare

[ Source](https://github.com/dwivedianuj9118/laravel-api-starter)[ Packagist](https://packagist.org/packages/dwivedianuj9118/laravel-api-starter)[ Docs](https://anujdwivedi.in)[ RSS](/packages/dwivedianuj9118-laravel-api-starter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

README.md
=========

[](#readmemd)

Laravel API Starter 🚀
=====================

[](#laravel-api-starter-)

- 🌐 **Website:**
- 🌐 **Company:**
- 📦 **Packagist:**
- 🐙 **GitHub:**

A **production-ready API starter package** for **Laravel 11+** designed to help you bootstrap APIs instantly without reinventing the wheel. This package is **opinionated but highly configurable**, tailored for real-world backend applications.

✨ Features
----------

[](#-features)

- ✅ **Dual Auth Support:** JWT Authentication (for mobile/external) &amp; Sanctum SPA Authentication.
- ✅ **Toggleable Auth:** Enable or disable JWT/Sanctum via config.
- ✅ **Standardized Responses:** Uniform JSON structure for success and error states.
- ✅ **API Versioning:** Pre-configured versioning (defaults to `/api/v1`).
- ✅ **Auto-Documentation:** Swagger/OpenAPI integration out of the box.
- ✅ **Robust Error Handling:** Global API exception handling (No more HTML errors in your API!).
- ✅ **Health Monitoring:** Dedicated `/health` endpoint for uptime checks.
- ✅ **Performance:** Built-in rate limiting and JSON-only enforcement.
- ✅ **Laravel 11 Ready:** Fully compatible with the latest Laravel structures.

📦 Requirements
--------------

[](#-requirements)

- **PHP:** 8.2+
- **Laravel:** 11+

---

📥 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require dwivedianuj9118/laravel-api-starter
```

### Configuration

[](#configuration)

Publish the configuration file to customize the behavior:

```
php artisan api-starter:install
```

### Environment Variables (`.env`)

[](#environment-variables-env)

Add or modify these variables to control your API behavior:

```
API_VERSION=v1
API_RATE_LIMIT=60

API_ENABLE_JWT=true
API_ENABLE_SANCTUM=true

API_AUTH_MODEL=App\Models\User
```

### JWT Guard

[](#jwt-guard)

You must define a JWT guard in `config/auth.php`.

```
'guards' => [

    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'jwt' => [
        'driver' => 'jwt',
        'provider' => 'users',
    ],

],
```

### Ensure provider exists

[](#ensure-provider-exists)

```
'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
    ],
],
```

---

🧯 Global API Exception Handling
-------------------------------

[](#-global-api-exception-handling)

The package automatically ensures JSON-only API exception responses.

If you want to customize exception rendering further, you may optionally integrate `ApiExceptionHandler` into your global exception flow.

### 📄 bootstrap/app.php (Laravel 11+)

[](#-bootstrapappphp-laravel-11)

```
use Dwivedianuj9118\ApiStarter\Exceptions\ApiExceptionHandler;

->withExceptions(function (Exceptions $exceptions): void {
    $exceptions->render(function (Throwable $e, $request) {
        if ($request->is('api/*')) {
            return ApiExceptionHandler::handle($e);
        }
    });
});
```

This ensures: No HTML error pages Consistent API error responses Validation &amp; auth errors normalized

### 📄 App\\Providers\\AppServiceProvider.php

[](#-appprovidersappserviceproviderphp)

```
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Http\Request;

public function boot(): void
{
    RateLimiter::for('api', function (Request $request) {
        return Limit::perMinute(
            config('api-starter.rate_limit.per_minute')
        )->by($request->ip());
    });
}
```

🔐 Preparing the Authentication Model (JWT &amp; Sanctum)
--------------------------------------------------------

[](#-preparing-the-authentication-model-jwt--sanctum)

This package supports **JWT authentication** and **Sanctum SPA authentication**.
Your authentication model (usually `User`) must be configured correctly.

---

### JWT &amp; Sanctum Model Setup (Required)

[](#jwt--sanctum-model-setup-required)

To enable **JWT** and **Sanctum** authentication, update your auth model (usually `User`) as follows:

1. **Implement `JWTSubject`**
2. **Use `HasApiTokens` trait**
3. **Add the two JWT methods**

```
use Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use HasApiTokens;

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims(): array
    {
        return [];
    }
}
```

If you are using JWT authentication, you must also define a `JWTSubject` interface in your model. And if you are using Sanctum authentication, you must also define a `HasApiTokens` trait in your model.

If you are using JWT and want to use middleware, you can use the `auth:jwt` middleware. And if you are using Sanctum, you can use the `auth:sanctum` middleware.

### Default:

[](#default)

🔐 Authentication
----------------

[](#-authentication)

### 1. JWT Authentication

[](#1-jwt-authentication)

Ideal for mobile apps and external clients.

- **Register:** `POST /api/v1/auth/register`
- **Login:** `POST /api/v1/auth/login`
- **Refresh:** `POST /api/v1/auth/refresh`
- **Logout:** `POST /api/v1/auth/logout`

\*To disable, set `API_ENABLE_JWT=false*`

### 2. Sanctum SPA Authentication

[](#2-sanctum-spa-authentication)

Optimized for first-party web applications.

- **Login:** `POST /api/v1/spa/login`
- **Logout:** `POST /api/v1/spa/logout`

\*To disable, set `API_ENABLE_SANCTUM=false*`

### Custom Auth Model

[](#custom-auth-model)

You can define which model is used for authentication (e.g., for an Admin panel):

```
API_AUTH_MODEL=App\Models\Admin
```

> **Note:** Your model must extend `Illuminate\Foundation\Auth\User` and use the `HasApiTokens` trait.

---

📊 API Response Format
---------------------

[](#-api-response-format)

All responses are returned as structured JSON.

### Success Response

[](#success-response)

```
{
  "success": true,
  "message": "Success",
  "data": {},
  "errors": null
}
```

### Error Response

[](#error-response)

```
{
  "success": false,
  "message": "Validation failed",
  "data": null,
  "errors": {
    "email": ["The email field is required."]
  }
}
```

---

Swagger Setup (Optional)
------------------------

[](#swagger-setup-optional)

Install Swagger:

```
composer require darkaonline/l5-swagger
php artisan vendor:publish --provider="L5Swagger\L5SwaggerServiceProvider"
```

Edit the generated file:

📄 config/l5-swagger.php

Update the annotations paths:

```
'annotations' => [
    base_path('app'),
    base_path('vendor/dwivedianuj9118/laravel-api-starter/src'),
],
```

### 🔐 REQUIRED: Sanctum Security Scheme (Swagger)

[](#-required-sanctum-security-scheme-swagger)

Make sure this exists in `config/l5-swagger.php`

```
'securityDefinitions' => [
    'securitySchemes' => [

        // JWT Authentication
        'bearerAuth' => [
            'type' => 'http',
            'scheme' => 'bearer',
            'bearerFormat' => 'JWT',
            'description' => 'JWT Authorization header using the Bearer scheme. Example: Bearer {token}',
        ],

        // Sanctum Authentication
        'sanctum' => [
            'type' => 'http',
            'scheme' => 'bearer',
            'description' => 'Sanctum token using Bearer scheme. Example: Bearer {token}',
            'in' => 'header',
        ],
    ],
],
```

Generate documentation:

```
php artisan l5-swagger:generate
```

Access Swagger UI at:

/api/documentation

---

🛠 Features in Detail
--------------------

[](#-features-in-detail)

### Health Check

[](#health-check)

Monitor your application status easily.

- **Endpoint:** `GET /api/v1/health`

### Rate Limiting

[](#rate-limiting)

Prevent abuse with built-in throttling (per IP).

- **Default:** 60 requests/min.
- **Customization:** Update `API_RATE_LIMIT` in your `.env`.

---

🧪 Testing
---------

[](#-testing)

Run the package test suite:

```
vendor/bin/phpunit
```

---

🚀 Roadmap
---------

[](#-roadmap)

- OAuth / Social Login support
- Multi-guard API configurations
- API Key-based authentication
- Webhook signature verification support

---

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

© 2026 **Dwivedianuj9118**

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance80

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

104d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/11f544e266a70d2f326cdfb15bfddc3f702c1f289a01e8fd51e9b49e24dd17e1?d=identicon)[dwivedianuj9118](/maintainers/dwivedianuj9118)

---

Top Contributors

[![dwivedianuj9118](https://avatars.githubusercontent.com/u/36004286?v=4)](https://github.com/dwivedianuj9118 "dwivedianuj9118 (5 commits)")

---

Tags

jwtlaravellaravel 11swaggersanctumboilerplatelaravel-authenticationlaravel-apilaravel-boilerplateAPI Starterlaravel rest apilaravel backendlaravel api startersaas backendapi starter kit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dwivedianuj9118-laravel-api-starter/health.svg)

```
[![Health](https://phpackages.com/badges/dwivedianuj9118-laravel-api-starter/health.svg)](https://phpackages.com/packages/dwivedianuj9118-laravel-api-starter)
```

###  Alternatives

[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
