PHPackages                             sioph/laravel10plate-authentication-sanctum - 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. sioph/laravel10plate-authentication-sanctum

ActiveLibrary

sioph/laravel10plate-authentication-sanctum
===========================================

Laravel Sanctum authentication package for Laravel10plate boilerplate

v1.0.0(11mo ago)03MITPHPPHP ^8.1

Since Jun 13Pushed 11mo agoCompare

[ Source](https://github.com/sioph/laravel10plate-authentication-sanctum)[ Packagist](https://packagist.org/packages/sioph/laravel10plate-authentication-sanctum)[ RSS](/packages/sioph-laravel10plate-authentication-sanctum/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel10plate Authentication Sanctum
=====================================

[](#laravel10plate-authentication-sanctum)

A modular Laravel Sanctum authentication package for the Laravel10plate boilerplate system. This package provides a complete authentication system with user management, role-based access, and API token authentication.

🚀 Features
----------

[](#-features)

- **Laravel Sanctum Token-based Authentication**
- **User Registration &amp; Login**
- **Role-based Access Control** (Admin/Staff)
- **User Status Management** (Active/Inactive)
- **Secure API Endpoints**
- **Auto-generated Migrations, Models, and Controllers**
- **Pre-configured Admin Account**

⚠️ Important Warning
--------------------

[](#️-important-warning)

> **🚨 RECOMMENDED FOR FRESH PROJECTS ONLY**
>
> This package is designed to work best with **fresh Laravel 10 installations** that do not have existing authentication features. Installing this package on projects with existing authentication systems may cause conflicts or unexpected behavior.
>
> **Before Installation:**
>
> - Ensure you're using **Laravel 10.x**
> - Verify you don't have existing authentication scaffolding (Laravel Breeze, Jetstream, UI, etc.)
> - Consider using this package on a **newly created Laravel project** for best results
> - Backup your project before installation if you have existing authentication code
>
> **If you have existing authentication:**
>
> - Review the conflicts that may arise with your current User model and migrations
> - Test thoroughly in a development environment before deploying to production

📋 Requirements
--------------

[](#-requirements)

- PHP ^8.1
- Laravel ^10.0
- Laravel Sanctum ^3.0

🛠 Installation
--------------

[](#-installation)

### Step 1: Install the Package

[](#step-1-install-the-package)

```
composer require sioph/laravel10plate-authentication-sanctum
```

### Step 2: Run Smart Installation Command

[](#step-2-run-smart-installation-command)

```
php artisan laravel10plate:install-auth
```

> 💡 **Smart Installation**: The installer automatically detects existing `User.php` model and users migration, then merges required code instead of overwriting. Backup files are created automatically.

### Step 3: Configure Database Connection

[](#step-3-configure-database-connection)

Configure your database in the `.env` file:

```
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password
```

> 📝 **Note**: Make sure your database exists and the credentials are correct before proceeding to the next step.

### Step 4: Run Migrations

[](#step-4-run-migrations)

```
php artisan migrate
```

📋 Backup Files Management
-------------------------

[](#-backup-files-management)

During installation, the package automatically creates backup files of your existing models and migrations to prevent data loss:

### Backup Location:

[](#backup-location)

- `app/Models/User.php.backup` - Backup of your original User model
- `database/migrations/*_create_users_table.php.backup` - Backup of your original users migration

### After Installation:

[](#after-installation)

1. **Verify the installation** - Check that your User model and migration are working correctly
2. **Test the functionality** - Ensure authentication is working as expected
3. **Review the changes** - Compare the modified files with the backup files
4. **Clean up backups** - Once you've verified everything is working correctly, you can safely delete the backup files:

```
# Remove User model backup (after verification)
rm app/Models/User.php.backup

# Remove migration backup (after verification)
rm database/migrations/*_create_users_table.php.backup
```

> 💡 **Tip**: Keep backup files until you're completely satisfied with the installation. They serve as a safety net in case you need to revert changes.

> ⚠️ **Important**: Only delete backup files after thorough testing in your development environment.

📁 What Gets Installed
---------------------

[](#-what-gets-installed)

### Migrations:

[](#migrations)

- `2014_09_25_055221_create_roles_table.php`
- `2014_09_26_034833_create_user_statuses_table.php`
- `2014_10_12_000000_create_users_table.php` (if not exists)

### Models:

[](#models)

- `app/Models/User.php` (if not exists)
- `app/Models/Role.php`
- `app/Models/UserStatus.php`

### Controllers:

[](#controllers)

- `app/Http/Controllers/AuthenticationController.php`

### API Routes:

[](#api-routes)

- Registration endpoint
- Login endpoint
- Logout endpoint (protected)

🔐 Default Admin Account
-----------------------

[](#-default-admin-account)

After migration, a default admin account is automatically created:

- **Email:** `admin@gmail.com`
- **Password:** `@Password1234`
- **Role:** Admin
- **Status:** Active

> ⚠️ **Important:** Change the default password in production!

📡 API Endpoints
---------------

[](#-api-endpoints)

### Public Endpoints

[](#public-endpoints)

#### Register Account

[](#register-account)

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

{
    "first_name": "John",
    "middle_name": "",
    "last_name": "Doe",
    "email": "john@example.com",
    "mobile_number": "1234567890",
    "password": "password123",
    "password_confirmation": "password123"
}
```

#### Login

[](#login)

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

{
    "email": "john@example.com",
    "password": "password123"
}
```

**Response:**

```
{
    "user": {
        "id": 1,
        "first_name": "John",
        "last_name": "Doe",
        "email": "john@example.com",
        "role": {
            "id": 2,
            "name": "Staff"
        },
        "status": {
            "id": 1,
            "name": "Active"
        }
    },
    "token": "1|abcdef123456..."
}
```

### Protected Endpoints (Requires Bearer Token)

[](#protected-endpoints-requires-bearer-token)

#### Logout

[](#logout)

```
POST /api/logout
Authorization: Bearer {your-token}
```

🔧 Configuration
---------------

[](#-configuration)

### Using the Token

[](#using-the-token)

After login, include the token in your API requests:

```
// JavaScript/Vue.js example
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;

// Or per request
axios.get('/api/protected-route', {
    headers: {
        'Authorization': `Bearer ${token}`
    }
});
```

### Token Expiration

[](#token-expiration)

Tokens expire after 8 hours by default. You can modify this in the `AuthenticationController.php`:

```
$token = $user->createToken('auth_token', ['*'], now()->addHours(8))->plainTextToken;
```

👥 User Roles &amp; Status
-------------------------

[](#-user-roles--status)

### Default Roles:

[](#default-roles)

- **Admin** - Full access
- **Staff** - Limited access

### User Statuses:

[](#user-statuses)

- **Active** - Can login
- **Inactive** - Cannot login

🔄 Re-installation
-----------------

[](#-re-installation)

If you accidentally run the install command again:

```
# Will show warning if already installed
php artisan laravel10plate:install-auth

# Force reinstall (overwrites existing files)
php artisan laravel10plate:install-auth --force
```

🛡 Security Features
-------------------

[](#-security-features)

- Password hashing using Laravel's Hash facade
- Token-based authentication with expiration
- Account status validation on login
- Input validation on registration and login
- Protected routes using Sanctum middleware

🗃 Database Schema
-----------------

[](#-database-schema)

### Users Table:

[](#users-table)

```
CREATE TABLE users (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    role_id BIGINT (Foreign Key -> roles.id),
    user_status_id BIGINT (Foreign Key -> user_statuses.id),
    first_name VARCHAR(255),
    middle_name VARCHAR(255) NULLABLE,
    last_name VARCHAR(255),
    contact_number VARCHAR(255) UNIQUE,
    email VARCHAR(255) UNIQUE,
    password VARCHAR(255) HASHED,
    password_reset_token VARCHAR(255) NULLABLE,
    password_reset_expires_at TIMESTAMP NULLABLE,
    email_verified_at TIMESTAMP NULLABLE,
    remember_token VARCHAR(100),
    created_at TIMESTAMP,
    updated_at TIMESTAMP
);
```

🐛 Troubleshooting
-----------------

[](#-troubleshooting)

### Issue: "Table 'users' already exists"

[](#issue-table-users-already-exists)

**Solution:** The package checks if the users table exists and skips creating it if it does.

### Issue: "Route already defined"

[](#issue-route-already-defined)

**Solution:** The package checks for existing routes before adding new ones.

### Issue: "Class 'Laravel\\Sanctum\\HasApiTokens' not found"

[](#issue-class-laravelsanctumhasapitokens-not-found)

**Solution:** Make sure Laravel Sanctum is installed:

```
composer require laravel/sanctum
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
```

### Issue: Token not working

[](#issue-token-not-working)

**Solution:** Check if you have the Sanctum middleware in your API routes:

```
Route::middleware('auth:sanctum')->group(function () {
    // Protected routes here
});
```

🔮 Future Features
-----------------

[](#-future-features)

- Password reset functionality
- Email verification
- Two-factor authentication
- Social login integration
- Audit logging

🤝 Contributing
--------------

[](#-contributing)

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

👨‍💻 Author
----------

[](#‍-author)

**Cilin John Rey**

- GitHub: [@cilinjohnrey](https://github.com/cilinjohnrey)
- Email:

🙏 Acknowledgments
-----------------

[](#-acknowledgments)

- Laravel team for the amazing framework
- Laravel Sanctum for secure API authentication
- Laravel10plate boilerplate system contributors

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance52

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

334d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e52af3e68f82870aa8befcb44d9c5a7e5cef5906dd8fbff41a31d906efe960bc?d=identicon)[cilinjohnrey](/maintainers/cilinjohnrey)

---

Top Contributors

[![cilinjohnrey](https://avatars.githubusercontent.com/u/50434281?v=4)](https://github.com/cilinjohnrey "cilinjohnrey (15 commits)")

### Embed Badge

![Health badge](/badges/sioph-laravel10plate-authentication-sanctum/health.svg)

```
[![Health](https://phpackages.com/badges/sioph-laravel10plate-authentication-sanctum/health.svg)](https://phpackages.com/packages/sioph-laravel10plate-authentication-sanctum)
```

###  Alternatives

[unopim/unopim

UnoPim Laravel PIM

9.4k1.8k](/packages/unopim-unopim)[spatie/mailcoach

Self-host Mailcoach

4007.0k](/packages/spatie-mailcoach)[laravel-enso/core

Main requirement &amp; dependency aggregator for Laravel Enso

3463.6k138](/packages/laravel-enso-core)

PHPackages © 2026

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