PHPackages                             pijler/laravel-common - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pijler/laravel-common

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pijler/laravel-common
=====================

Simple package with several common features in Laravel applications.

v0.9.3(1mo ago)2764↓45.7%MITPHPPHP ^8.3CI passing

Since Oct 20Pushed 1mo agoCompare

[ Source](https://github.com/Pijler/laravel-common)[ Packagist](https://packagist.org/packages/pijler/laravel-common)[ RSS](/packages/pijler-laravel-common/feed)WikiDiscussions main Synced 4d ago

READMEChangelog (10)Dependencies (36)Versions (19)Used By (0)

📌 Laravel Common
================

[](#-laravel-common)

A Laravel package that contains common functionalities I use in almost all projects I develop. This package includes traits, helpers, macros, commands, and other utilities that speed up development.

### 📦 Installation

[](#-installation)

You can install the package via Composer:

```
composer require pijler/laravel-common
```

The package will be automatically discovered by Laravel.

### 🧩 Features

[](#-features)

#### 🎯 Actions

[](#-actions)

Abstract base class for executing actions in a clean and organized way:

```
use Common\Support\Action;

class CreateUserAction extends Action
{
    public function __construct(
        private string $name,
        private string $email
    ) {}

    protected function handle()
    {
        return User::create([
            'name' => $this->name,
            'email' => $this->email,
        ]);
    }
}

// Usage
$user = CreateUserAction::execute(
    name: 'João Pedro',
    email: 'joao@example.com',
);

// With conditions
CreateUserAction::executeIf($shouldCreate, 'João Pedro', 'joao@example.com');
CreateUserAction::executeUnless($shouldNotCreate, 'João Pedro', 'joao@example.com');
```

#### 🔐 Two-Factor Authentication

[](#-two-factor-authentication)

Trait for implementing two-factor authentication:

```
use Common\Traits\HasTwoFactor;

class User extends Model
{
    use HasTwoFactor;
}

// Check if user has 2FA enabled
$user->hasTwoFactor();

// Get recovery codes
$codes = $user->recoveryCodes();

// Replace recovery code
$user->replaceRecoveryCode($oldCode);

// Get QR Code SVG
$qrCode = $user->twoFactorQrCodeSvg();

// Get QR Code URL
$url = $user->twoFactorQrCodeUrl();
```

#### 📱 User Agent Detection

[](#-user-agent-detection)

Class for detecting browser and device information:

```
use Common\Support\Agent;

$agent = new Agent();

// Device information
$agent->isMobile();
$agent->isTablet();
$agent->isDesktop();

// Browser information
$agent->browser(); // Chrome, Firefox, Safari, etc.

// Operating system information
$agent->platform(); // Windows, macOS, Linux, etc.
```

#### 🚨 Alert System

[](#-alert-system)

Alert system with typed exceptions:

```
use Common\Enum\Alert;
use Common\Exceptions\Alert\InfoException;
use Common\Exceptions\Alert\ErrorException;
use Common\Exceptions\Alert\WarningException;

// Throw alert exceptions
InfoException::make('Info Message!');
ErrorException::make('Error Message!');
WarningException::make('Warning Message!');

// Helpers to check exceptions
check_exception($exception); // bool
throw_exception($exception); // void
```

#### 📨 Storage Channel

[](#-storage-channel)

Notification channel that saves emails to files and database:

```
use Common\Channel\StorageChannel;

// Configure callback for custom path
StorageChannel::storagePathUsing(function ($notification) {
    return "/custom/path/{$notification->id}.html";
});

// Use in notifications
class WelcomeNotification extends Notification
{
    public function via($notifiable)
    {
        return ['storage'];
    }
}

// Customize the model/relation per notification
class InvoiceStoredNotification extends Notification
{
    public function via($notifiable)
    {
        return ['storage'];
    }

    public function storageRelation($notifiable)
    {
        return $notifiable->archivedEmails();
    }
}
```

#### 🛠️ Macros

[](#️-macros)

Useful macros for Eloquent, RedirectResponse and TestResponse:

##### Eloquent Builder

[](#eloquent-builder)

```
// Get first random record
User::firstRandom();
```

##### RedirectResponse

[](#redirectresponse)

```
// Alert messages
return redirect()->info('Info Message!');
return redirect()->error('Error Message!');
return redirect()->success('Success Message!');
return redirect()->warning('Warning Message!');

// Custom message
return redirect()->message('Message text', Alert::INFO);

// Custom action
return redirect()->action(ActionData::from([
    'text' => 'Undo',
    'method' => 'patch',
    'url' => "/users/{$user->id}/restore",
]));
```

##### TestResponse

[](#testresponse)

```
// Message assertions
$response->assertInfoMessage('Info Message!');
$response->assertErrorMessage('Error Message!');
$response->assertSuccessMessage('Success Message!');
$response->assertWarningMessage('Warning Message!');

// Action assertion
$response->assertAction(ActionData::from([
    'text' => 'Undo',
    'method' => 'patch',
    'url' => "/users/{$user->id}/restore",
]));
```

##### Inertia.js (if available)

[](#inertiajs-if-available)

```
// Automatic filters
return Inertia::render('Users/Index')->filters([
    'role' => 'admin',
    'status' => 'active',
]);

// Pagination parameters
return Inertia::render('Users/Index')->params([
    'page' => 1,
    'limit' => 10,
    'sort' => 'name',
]);
```

#### 🗄️ Database Utilities

[](#️-database-utilities)

##### Rename Migrations Command

[](#rename-migrations-command)

```
php artisan migrate:rename
```

This command renames migration files to follow a consistent pattern.

#### 🔒 File Encryption Commands

[](#-file-encryption-commands)

Commands for encrypting and decrypting files:

##### Encrypt File Command

[](#encrypt-file-command)

```
php artisan file:encrypt --filename=.npmrc
```

**Options:**

- `--key`: The encryption key (if not provided, a random key will be generated)
- `--cipher`: The encryption cipher (default: `AES-256-CBC`)
- `--path`: Path to write the encrypted file (default: `base_path()`)
- `--filename`: Filename of the file to encrypt (required)
- `--prune`: Delete the original file after encryption
- `--force`: Overwrite the existing encrypted file

**Interactive Mode:**If run interactively without options, the command will prompt for:

- Filename to encrypt
- Encryption key (with option to generate a random key or provide your own)

**Examples:**

```
# Encrypt a file with automatic key generation
php artisan file:encrypt --filename=.npmrc

# Encrypt with a specific key
php artisan file:encrypt --filename=.npmrc --key="your-encryption-key"

# Encrypt and delete original file
php artisan file:encrypt --filename=.npmrc --prune

# Encrypt with custom cipher
php artisan file:encrypt --filename=.npmrc --cipher=AES-128-CBC

# Encrypt and force overwrite existing encrypted file
php artisan file:encrypt --filename=.npmrc --force
```

The encrypted file will be saved with `.encrypted` extension (e.g., `.npmrc.encrypted`).

##### Decrypt File Command

[](#decrypt-file-command)

```
php artisan file:decrypt --filename=.npmrc.encrypted
```

**Options:**

- `--key`: The decryption key (if not provided, will use `LARAVEL_ENV_ENCRYPTION_KEY` from environment)
- `--cipher`: The encryption cipher (default: `AES-256-CBC`)
- `--path`: Path to write the decrypted file (default: `base_path()`)
- `--filename`: Filename of the encrypted file to decrypt (required, must end with `.encrypted`)
- `--force`: Overwrite the existing decrypted file

**Interactive Mode:**If run interactively without options, the command will prompt for:

- Filename to decrypt
- Decryption key (if not available in environment)

**Examples:**

```
# Decrypt a file (uses LARAVEL_ENV_ENCRYPTION_KEY from .env)
php artisan file:decrypt --filename=.npmrc.encrypted

# Decrypt with a specific key
php artisan file:decrypt --filename=.npmrc.encrypted --key="your-encryption-key"

# Decrypt with base64 encoded key
php artisan file:decrypt --filename=.npmrc.encrypted --key="base64:encoded-key"

# Decrypt and force overwrite existing file
php artisan file:decrypt --filename=.npmrc.encrypted --force
```

The decrypted file will be saved without the `.encrypted` extension.

#### 🎨 Enum Helpers

[](#-enum-helpers)

Trait for enums with useful methods:

```
use Common\Traits\EnumMethods;

enum Status: string
{
    use EnumMethods;

    case ACTIVE = 'active';
    case INACTIVE = 'inactive';
}

// Available methods
Status::keys(); // ['ACTIVE', 'INACTIVE']
Status::values(); // ['active', 'inactive']
```

#### 📁 Media Library Extensions

[](#-media-library-extensions)

Extensions for Spatie Media Library:

- **CustomFileNamer**: Custom file naming
- **CustomPathGenerator**: Custom path generation

#### 🔗 Notification URL

[](#-notification-url)

Trait for generating notification URLs:

```
use Common\Traits\NotificationUrl;

class User extends Model
{
    use NotificationUrl;
}

// Generate URL for notification
$url = $user->notificationUrl($notification);
```

#### 🏗️ Builder Helpers

[](#️-builder-helpers)

Trait for adding useful methods to Eloquent Builders:

```
use Common\Traits\HasBuilder;

class User extends Model
{
    use HasBuilder;
}

// Methods available automatically on builders
User::query()->whereActive();
User::query()->whereInactive();
```

#### ⚡ Horizon Queue

[](#-horizon-queue)

Trait for working with Laravel Horizon:

```
use Common\Traits\HorizonQueue;

class ProcessDataJob implements ShouldQueue
{
    use HorizonQueue;
}
```

### 📝 License

[](#-license)

Open-source under the [MIT license](LICENSE).

🚀 Thanks!
---------

[](#-thanks)

*This package contains common functionalities I use in my Laravel projects. Feel free to use and contribute!*

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance90

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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 ~15 days

Total

15

Last Release

48d ago

PHP version history (2 changes)v0.1.0PHP ^8.2

v0.8.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/5256615ef2ba165b92bdf89908082480fb12be597c607637262e9fe61b5b2b22?d=identicon)[joaopalopes24@gmail.com](/maintainers/joaopalopes24@gmail.com)

---

Top Contributors

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

---

Tags

laravelpackagecommon

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/pijler-laravel-common/health.svg)

```
[![Health](https://phpackages.com/badges/pijler-laravel-common/health.svg)](https://phpackages.com/packages/pijler-laravel-common)
```

###  Alternatives

[firefly-iii/data-importer

Firefly III Data Import Tool.

8035.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[creasi/laravel-nusa

A Laravel package that aim to provide Indonesia' Administrative Data

997.9k3](/packages/creasi-laravel-nusa)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[pdazcom/laravel-referrals

A referrals system for a laravel projects.

291.5k](/packages/pdazcom-laravel-referrals)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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