PHPackages                             amranibrahem/laravel-jwt-setup - 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. amranibrahem/laravel-jwt-setup

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

amranibrahem/laravel-jwt-setup
==============================

Automatically install and configure JWT authentication for Laravel with a single command - complete setup with controllers, requests, responses, and routes

v2.1.3(5mo ago)011MITPHPPHP ^8.0

Since Nov 23Pushed 5mo agoCompare

[ Source](https://github.com/AmranIbrahem/laravel-jwt-setup)[ Packagist](https://packagist.org/packages/amranibrahem/laravel-jwt-setup)[ Docs](https://github.com/amranibrahem/laravel-jwt-setup)[ RSS](/packages/amranibrahem-laravel-jwt-setup/feed)WikiDiscussions master Synced 1mo ago

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

Laravel JWT Auto Setup
======================

[](#laravel-jwt-auto-setup)

🚀 **Automated JWT Authentication Setup for Laravel Applications**

A powerful Laravel package that automatically installs and configures JWT authentication with a single command, saving you hours of manual setup.

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

[](#-features)

- ✅ **One-command installation** - Complete JWT setup with `php artisan jwt:auto-setup`
- ✅ **Automatic package installation** - Installs `tymon/jwt-auth` via Composer
- ✅ **Smart configuration** - Auto-configures auth guards and JWT settings
- ✅ **Model enhancement** - Updates User model with JWTSubject implementation
- ✅ **Complete file generation** - Creates controllers, requests, responses, and routes
- ✅ **Professional code structure** - Follows Laravel best practices
- ✅ **Error handling** - Comprehensive error reporting and rollback
- ✅ **Validation integration** - Custom form requests with validation
- ✅ **Standardized responses** - Consistent JSON response format

🚀 Installation
--------------

[](#-installation)

**You can install the package via Composer:**

```
composer require amranibrahem/jwt-setup
```

📖 Usage
-------

[](#-usage)

**Run the auto-setup command:**

```
php artisan jwt:auto-setup
```

What This Command Does:
-----------------------

[](#what-this-command-does)

📦 **Installs tymon/jwt-auth package**
Automatically installs the required JWT package via Composer

📁 **Publishes JWT configuration files**
Publishes all necessary configuration files for JWT setup

🔑 **Generates JWT secret key**
Creates a secure JWT secret key for token signing

⚙️ **Updates auth configuration**
Automatically configures auth guards in `config/auth.php`

👤 **Enhances User model with JWT methods**
Updates the User model to implement JWTSubject interface

🛠 **Creates professional file structure:**

• **Response class** - Standardized JSON response format
• **Form requests** - Register &amp; Login validation classes
• **AuthController** - Complete authentication logic
• **API routes** - Ready-to-use authentication endpoints

🎯 Generated File Structure
--------------------------

[](#-generated-file-structure)

```
app/
├── Http/
│   ├── Controllers/
│   │   └── AuthController.php
│   ├── Requests/
│   │   └── Auth/
│   │       ├── LoginRequest.php
│   │       └── RegisterRequest.php
│   └── Responses/
│       └── Response.php
└── Models/
└── User.php (updated)

```

🔌 API Endpoints
---------------

[](#-api-endpoints)

After setup, you'll have these ready-to-use endpoints:

### Public Routes

[](#public-routes)

- `POST /api/auth/register` - User registration
- `POST /api/auth/login` - User login

### Protected Routes (Require JWT)

[](#protected-routes-require-jwt)

- `POST /api/auth/logout` - User logout
- `POST /api/auth/refresh` - Refresh JWT token

🎨 Code Examples
---------------

[](#-code-examples)

**Generated AuthController Methods**

```
// Registration
public function register(RegisterRequest $request)
{
// Handles user registration with validation
// Returns: User data + JWT token
}

// Login
public function login(LoginRequest $request)
{
// Handles user authentication
// Returns: User data + JWT token
}

// Logout
public function logout(Request $request)
{
// Invalidates JWT token
// Returns: Success message
}
```

**Professional Response Format**

```
{
"message": "Login successful",
"data": {
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2023-01-01 12:00:00"
},
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}
```

**Enhanced User Model**

```
