PHPackages                             sky337/secure-api - 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. [API Development](/categories/api)
4. /
5. sky337/secure-api

ActiveLibrary[API Development](/categories/api)

sky337/secure-api
=================

A secure API package for Laravel with JWT and RBAC.

v1.0.2(4mo ago)00MITPHPPHP ^8.1

Since Feb 22Pushed 4mo agoCompare

[ Source](https://github.com/sky337/secure-api)[ Packagist](https://packagist.org/packages/sky337/secure-api)[ RSS](/packages/sky337-secure-api/feed)WikiDiscussions main Synced today

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

SecureAPI Laravel Package
=========================

[](#secureapi-laravel-package)

A professional, scalable package for Laravel applications providing JWT Authentication, a robust Role &amp; Permission system (RBAC), and standardized API responses.

Features
--------

[](#features)

- **JWT Integration**: Seamlessly works with `php-open-source-saver/jwt-auth`.
- **RBAC System**: Role and Permission models with custom pivot tables (`role_permission`, `user_role`).
- **Standardized Responses**: Consistent JSON response structure (`status`, `message`, `data`, `errors`).
- **Middleware support**: Protect routes using `role:admin` syntax.
- **Easy Integration**: Package-specific trait for User models and controllers.

---

Installation
------------

[](#installation)

### 1. Require via Composer

[](#1-require-via-composer)

If the package is not yet on Packagist, add the following to your main app's `composer.json`:

```
"repositories": [
    {
        "type": "path",
        "url": "../SecureAPI",
        "options": {
            "symlink": true
        }
    }
]
```

Then run:

```
composer require sky337/secure-api
```

### 2. Publish Configuration &amp; Migrations

[](#2-publish-configuration--migrations)

```
php artisan vendor:publish --provider="Sky337\SecureAPI\Providers\SecureAPIServiceProvider"
```

### 3. Run Migrations

[](#3-run-migrations)

```
php artisan migrate
```

---

Configuration
-------------

[](#configuration)

The package configuration is available at `config/secure-api.php`. You can customize the default roles, permissions, and API response keys here.

---

Usage
-----

[](#usage)

### User Model Integration

[](#user-model-integration)

Add the `HasRoles` trait to your `User` model:

```
use Sky337\SecureAPI\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
}
```

### Roles &amp; Permissions

[](#roles--permissions)

```
$user->assignRole('admin');

if ($user->hasRole('admin')) {
    // Logic for admin
}

if ($user->hasAnyRole(['admin', 'editor'])) {
    // Logic for admin or editor
}
```

### Standard API Responses

[](#standard-api-responses)

Use the `ApiResponse` class or `ApiResponseTrait` in your controllers:

```
use Sky337\SecureAPI\Classes\ApiResponse;

return ApiResponse::success($data, 'User fetched successfully');
return ApiResponse::error('Something went wrong', 400);
return ApiResponse::validationError($validator->errors());
```

**Standard Response Structure:**

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

---

Middleware usage
----------------

[](#middleware-usage)

Protect your routes using the `role` middleware alias:

```
Route::middleware(['auth:api', 'role:admin'])->group(function () {
    Route::get('/dashboard', [AdminController::class, 'index']);
});

Route::middleware(['role:admin,manager'])->get('/reports', [ReportController::class, 'index']);
```

---

Example Routes
--------------

[](#example-routes)

```
use Illuminate\Support\Facades\Route;
use Sky337\SecureAPI\Classes\ApiResponse;

Route::post('/login', [AuthController::class, 'login']);

Route::middleware(['auth:api'])->group(function () {
    Route::get('/profile', function() {
        return ApiResponse::success(auth()->user());
    });
});
```

---

Contribution Guide
------------------

[](#contribution-guide)

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

---

License
-------

[](#license)

Distributed under the MIT License. See `LICENSE` for more information.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance76

Regular maintenance activity

Popularity0

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

Every ~0 days

Total

3

Last Release

131d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/sky337-secure-api/health.svg)

```
[![Health](https://phpackages.com/badges/sky337-secure-api/health.svg)](https://phpackages.com/packages/sky337-secure-api)
```

###  Alternatives

[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.6k3](/packages/defstudio-telegraph)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[rapidez/core

Rapidez Core

1823.5k72](/packages/rapidez-core)

PHPackages © 2026

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