Template Laravel API-only project with Sanctum
yarazan/laravel-sanctum-api-only is a Laravel package for template laravel api-only project with sanctum.
It currently has 0 GitHub stars and 1 downloads on Packagist (latest version v1.0.0).
Install it with composer require yarazan/laravel-sanctum-api-only.
Discover more Laravel packages by yarazan
or browse all Laravel packages to compare alternatives.
Last updated
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.
HasUuid trait (App\Traits\HasUuid) to automatically handle UUID generation and binary storage (16 bytes).BinaryUuidExists for checking object existence during validation steps./register and /login routes.['token'] structure./register and /login requests.HasApiTokens as HasApiTokensWithLocation to track device name and location alongside tokens.root or admin).app:generate-root-password generates a secure root user password and stores it in the .env file.
.env file exists before running the command.root role (or custom role based on your .env configuration)..env file.auth:sanctum middleware.git clone <repository_url>
cd <project_name>
composer install
.env.example file to .env:
cp .env.example .env
php artisan key:generate
.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
BINARY(16).UUID type.Generate a root password:
php artisan app:generate-root-password
.env file.Run seeders to create the root role and root user:
php artisan db:seed
routes/api.php file.Route::middleware('auth:sanctum')->group(function () {
// Your protected routes here
});
POST /register
Content-Type: application/json
{
"name": "Your Name",
"email": "[email protected]",
"password": "securepassword",
"password_confirmation": "securepassword"
}
POST /login
Content-Type: application/json
{
"email": "[email protected]",
"password": "securepassword"
}
Role and User models.Role model.BinaryUuidExists ensures UUID existence during validation./register and /login routes ensure robust input validation.Feel free to fork this repository and submit pull requests. Contributions are always welcome!
This project is open-sourced and licensed under the MIT License.