PHPackages                             yarazan/laravel-sanctum-api-only - 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. [Framework](/categories/framework)
4. /
5. yarazan/laravel-sanctum-api-only

ActiveProject[Framework](/categories/framework)

yarazan/laravel-sanctum-api-only
================================

Template Laravel API-only project with Sanctum

v1.0.0(1y ago)01MITPHPPHP ^8.2

Since Nov 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/YaraZan/laravel-sanctum-api-only)[ Packagist](https://packagist.org/packages/yarazan/laravel-sanctum-api-only)[ RSS](/packages/yarazan-laravel-sanctum-api-only/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (12)Versions (7)Used By (0)

[![image](https://private-user-images.githubusercontent.com/115586290/388072172-db98d9d8-324c-48ef-ad83-54a059081e05.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODIxMzM3NDYsIm5iZiI6MTc4MjEzMzQ0NiwicGF0aCI6Ii8xMTU1ODYyOTAvMzg4MDcyMTcyLWRiOThkOWQ4LTMyNGMtNDhlZi1hZDgzLTU0YTA1OTA4MWUwNS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwNjIyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDYyMlQxMzA0MDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mYWU4OGM1NmYyMjI5ZTQzODg3NjUyZmI1N2Y0NDAyOWNiNThmZDQ5ODdhYmYzMDc0ZGUyZDc5NTc2ZDgxY2Q5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZyZXNwb25zZS1jb250ZW50LXR5cGU9aW1hZ2UlMkZwbmcifQ.RhgHUSxTiNQJ0ixcl1E8_8i7US2fNz12eVMCDilAWRQ)](https://private-user-images.githubusercontent.com/115586290/388072172-db98d9d8-324c-48ef-ad83-54a059081e05.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODIxMzM3NDYsIm5iZiI6MTc4MjEzMzQ0NiwicGF0aCI6Ii8xMTU1ODYyOTAvMzg4MDcyMTcyLWRiOThkOWQ4LTMyNGMtNDhlZi1hZDgzLTU0YTA1OTA4MWUwNS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwNjIyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDYyMlQxMzA0MDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mYWU4OGM1NmYyMjI5ZTQzODg3NjUyZmI1N2Y0NDAyOWNiNThmZDQ5ODdhYmYzMDc0ZGUyZDc5NTc2ZDgxY2Q5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZyZXNwb25zZS1jb250ZW50LXR5cGU9aW1hZ2UlMkZwbmcifQ.RhgHUSxTiNQJ0ixcl1E8_8i7US2fNz12eVMCDilAWRQ)

 Laravel Sanctum API Only
==========================

[](#-laravel-sanctum-api-only-)

[![Build Status](https://github.com/YaraZan/laravel-sanctum-api-only/actions/workflows/laravel.yml/badge.svg)](https://github.com/YaraZan/laravel-sanctum-api-only/actions)[![Build Status](https://github.com/YaraZan/laravel-sanctum-api-only/actions/workflows/php.yml/badge.svg)](https://github.com/YaraZan/laravel-sanctum-api-only/actions)[![Total Downloads](https://camo.githubusercontent.com/1aef8a9c0f0dbd543bd16484be63f6661f4c0276d2d06eab481011dfc80b1deb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796172617a616e2f6c61726176656c2d73616e6374756d2d6170692d6f6e6c79)](https://packagist.org/packages/yarazan/laravel-sanctum-api-only)[![Latest Stable Version](https://camo.githubusercontent.com/ab778ba4edd4fa7940ba726b8aaa424b6d1a1b497c487da2ff0c493d1d10da8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796172617a616e2f6c61726176656c2d73616e6374756d2d6170692d6f6e6c79)](https://packagist.org/packages/yarazan/laravel-sanctum-api-only)[![License](https://camo.githubusercontent.com/85edac467347a571d7ea7260c3f809d05094cb28ea636e3ec3a219e55c1e7413/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f796172617a616e2f6c61726176656c2d73616e6374756d2d6170692d6f6e6c79)](https://packagist.org/packages/yarazan/laravel-sanctum-api-only)

### Overview

[](#overview)

This Laravel project is an **API-only** application designed for robust authentication and authorization using Laravel Sanctum. It includes seamless support for handling **UUIDs in binary format** across both **MySQL** and **PostgreSQL**, along with essential features like root user management, seeders, and role-based policies.

Key Features
------------

[](#key-features)

### 1. **UUID Handling**

[](#1-uuid-handling)

- Models requiring UUIDs can use the `HasUuid` trait (`App\Traits\HasUuid`) to automatically handle UUID generation and binary storage (16 bytes).
- Custom validation rule: `BinaryUuidExists` for checking object existence during validation steps.
- Database configuration supports both MySQL and PostgreSQL UUID handling.

### 2. **API Authentication**

[](#2-api-authentication)

- **Sanctum-based authentication** with `/register` and `/login` routes.
- Upon successful authentication, the server responds with a JSON object containing a `['token']` structure.
- Default **custom validation rules** are implemented for both `/register` and `/login` requests.

### 3. **Extended Token Management**

[](#3-extended-token-management)

- Includes a modified version of `HasApiTokens` as `HasApiTokensWithLocation` to track **device name** and **location** alongside tokens.

### 4. **Root User Management**

[](#4-root-user-management)

- Pre-configured **root user** with a dedicated role (`root` or `admin`).
- Artisan command `app:generate-root-password` generates a secure root user password and stores it in the `.env` file.
    - Ensure the `.env` file exists before running the command.
- Default seeders create:
    - `root` role (or custom role based on your `.env` configuration).
    - Root user with credentials stored in the `.env` file.

### 5. **Role Management**

[](#5-role-management)

- Includes an implemented policy and controller for the **Role** model.
- Role-based access control is applied using Sanctum's `auth:sanctum` middleware.

Getting Started
---------------

[](#getting-started)

### 1. **Installation**

[](#1-installation)

1. Clone the repository: ```
    git clone
    ```
2. Navigate to the project directory: ```
    cd
    ```
3. Install dependencies: ```
    composer install
    ```
4. Copy the `.env.example` file to `.env`: ```
    cp .env.example .env
    ```
5. Generate the application key: ```
    php artisan key:generate
    ```

### 2. **Database Configuration**

[](#2-database-configuration)

- Configure your database connection in the `.env` file: ```
    DB_CONNECTION=mysql      # or pgsql
    DB_HOST=127.0.0.1
    DB_PORT=3306             # or 5432 for PostgreSQL
    DB_DATABASE=your_db
    DB_USERNAME=your_user
    DB_PASSWORD=your_password
    ```

### 3. **UUID Configuration**

[](#3-uuid-configuration)

- For MySQL, UUIDs are stored as `BINARY(16)`.
- For PostgreSQL, UUIDs use the native `UUID` type.

---

Usage
-----

[](#usage)

### Root User Setup

[](#root-user-setup)

1. Generate a root password:

    ```
    php artisan app:generate-root-password
    ```

    - This will generate a secure password in the `.env` file.
2. Run seeders to create the root role and root user:

    ```
    php artisan db:seed
    ```

### Routes

[](#routes)

- Define your API routes in the `routes/api.php` file.
- Protect routes with Sanctum middleware: ```
    Route::middleware('auth:sanctum')->group(function () {
        // Your protected routes here
    });
    ```

### Example Endpoints

[](#example-endpoints)

#### Registration

[](#registration)

```
POST /register
Content-Type: application/json

{
    "name": "Your Name",
    "email": "your@example.com",
    "password": "securepassword",
    "password_confirmation": "securepassword"
}
```

#### Login

[](#login)

```
POST /login
Content-Type: application/json

{
    "email": "your@example.com",
    "password": "securepassword"
}
```

### Seeders

[](#seeders)

- Default seeders are included for `Role` and `User` models.

Policies and Validation
-----------------------

[](#policies-and-validation)

### Policies

[](#policies)

- **Role Policy** is pre-configured for the `Role` model.

### Validation Rules

[](#validation-rules)

- `BinaryUuidExists` ensures UUID existence during validation.
- Custom rules for `/register` and `/login` routes ensure robust input validation.

Contributing
------------

[](#contributing)

Feel free to fork this repository and submit pull requests. Contributions are always welcome!

License
-------

[](#license)

This project is open-sourced and licensed under the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Unknown

Total

1

Last Release

592d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/115586290?v=4)[Ярослав Потёмкин](/maintainers/YaraZan)[@YaraZan](https://github.com/YaraZan)

---

Top Contributors

[![YaraZan](https://avatars.githubusercontent.com/u/115586290?v=4)](https://github.com/YaraZan "YaraZan (7 commits)")

---

Tags

frameworklaravel

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/yarazan-laravel-sanctum-api-only/health.svg)

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

###  Alternatives

[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[bagisto/bagisto

Bagisto Laravel E-Commerce

27.6k172.1k9](/packages/bagisto-bagisto)[krayin/laravel-crm

Krayin CRM

23.2k33.6k1](/packages/krayin-laravel-crm)[nasirkhan/laravel-starter

A CMS like modular Laravel starter project.

1.4k2.7k](/packages/nasirkhan-laravel-starter)[codewithdennis/larament

Larament is a time-saving starter kit to quickly launch Laravel 13.x projects. It includes FilamentPHP 5.x pre-installed and configured, along with additional tools and features to streamline your development workflow.

3991.8k](/packages/codewithdennis-larament)[ercogx/laravel-filament-starter-kit

This is a Filament v5 Starter Kit for Laravel 13, designed to accelerate the development of Filament-powered applications.

461.7k](/packages/ercogx-laravel-filament-starter-kit)

PHPackages © 2026

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