PHPackages                             nunomaduro/essentials - 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. nunomaduro/essentials

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

nunomaduro/essentials
=====================

Just better defaults for your Laravel projects.

v1.2.0(2mo ago)1.2k317.5k—8%71[1 issues](https://github.com/nunomaduro/essentials/issues)20MITPHPPHP ^8.3.0CI passing

Since Jun 4Pushed 2mo ago14 watchersCompare

[ Source](https://github.com/nunomaduro/essentials)[ Packagist](https://packagist.org/packages/nunomaduro/essentials)[ Fund](https://www.paypal.com/paypalme/enunomaduro)[ GitHub Sponsors](https://github.com/nunomaduro)[ RSS](/packages/nunomaduro-essentials/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (6)Used By (20)

[   ![Logo for essentials](art/header-light.png) ](https://nunomaduro.com/)Essentials
==========

[](#essentials)

 [![Build Status](https://github.com/nunomaduro/essentials/actions/workflows/tests.yml/badge.svg)](https://github.com/nunomaduro/essentials/actions) [![Total Downloads](https://camo.githubusercontent.com/a8a8a2e1039a45e052bb07a528acbd25ce076fce17e3ae1f32c5a6759792bbde/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e756e6f6d616475726f2f657373656e7469616c73)](https://packagist.org/packages/nunomaduro/essentials) [![Latest Stable Version](https://camo.githubusercontent.com/374ce8afbe50eeec78438eb81312fedca3f7115a619087fcff89ce0ca671f5a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e756e6f6d616475726f2f657373656e7469616c73)](https://packagist.org/packages/nunomaduro/essentials) [![License](https://camo.githubusercontent.com/039e6a6a78acdca5d223fcc2132bbc4c15d226a30f7a718a463e5903b4ce6b88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e756e6f6d616475726f2f657373656e7469616c73)](https://packagist.org/packages/nunomaduro/essentials)

Essentials provide **better defaults** for your Laravel applications including strict models, automatically eagerly loaded relationships, immutable dates, and more!

> **Requires [PHP 8.3+](https://php.net/releases/)**, **[Laravel 11+](https://laravel.com/docs/11.x/)**.

> **Note:** This package modifies the default behavior of Laravel. **It is recommended to use it in new projects** or when you are comfortable with the changes it introduces.

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

[](#installation)

⚡️ Get started by requiring the package using [Composer](https://getcomposer.org):

```
composer require nunomaduro/essentials
```

Features
--------

[](#features)

All features are optional and configurable in `config/essentials.php`.

You may publish the configuration file with:

```
php artisan vendor:publish --tag=essentials-config
```

Table of Contents
-----------------

[](#table-of-contents)

- [Strict Models](#-strict-models)
- [Auto Eager Loading](#-auto-eager-loading)
- [Optional Unguarded Models](#-optional-unguarded-models)
- [Immutable Dates](#-immutable-dates)
- [Force HTTPS](#-force-https)
- [Safe Console](#-safe-console)
- [Asset Prefetching](#-asset-prefetching)
- [Prevent Stray Requests](#-prevent-stray-requests)
- [Fake Sleep](#-fake-sleep)
- [Artisan Commands](#-artisan-commands)
    - [make:action](#makeaction)
    - [essentials:pint](#essentialspint)
    - [essentials:rector](#essentialsrector)

### ✅ Strict Models

[](#-strict-models)

Improves how Eloquent handles undefined attributes, lazy loading, and invalid assignments.

- Accessing a missing attribute throws an error.
- Lazy loading is blocked unless explicitly allowed.
- Setting undefined attributes throws instead of failing silently.

**Why:** Avoids subtle bugs and makes model behavior easier to reason about.

---

### ⚡️ Auto Eager Loading

[](#️-auto-eager-loading)

Automatically eager loads relationships defined in the model's `$with` property.

**Why:** Reduces N+1 query issues and improves performance without needing `with()` everywhere.

---

### 🔓 Optional Unguarded Models

[](#-optional-unguarded-models)

Disables Laravel's mass assignment protection globally (opt-in).

**Why:** Useful in trusted or local environments where you want to skip defining `$fillable`.

---

### 🕒 Immutable Dates

[](#-immutable-dates)

Uses `CarbonImmutable` instead of mutable date objects across your app.

**Why:** Prevents unexpected date mutations and improves predictability.

---

### 🔒 Force HTTPS

[](#-force-https)

Forces all generated URLs to use `https://`.

**Why:** Ensures all traffic uses secure connections by default.

---

### 🛑 Safe Console

[](#-safe-console)

Blocks potentially destructive Artisan commands in production (e.g., `migrate:fresh`).

**Why:** Prevents accidental data loss and adds a safety net in sensitive environments.

---

### 🚀 Asset Prefetching

[](#-asset-prefetching)

Configures Laravel Vite to preload assets more aggressively.

**Why:** Improves front-end load times and user experience.

---

### 🔄 Prevent Stray Requests

[](#-prevent-stray-requests)

Configures Laravel Http Facade to prevent stray requests.

**Why:** Ensure every HTTP calls during tests have been explicitly faked.

---

### 😴 Fake Sleep

[](#-fake-sleep)

Configures Laravel Sleep Facade to be faked.

**Why:** Avoid unexpected sleep during testing cases.

### 🏗️ Artisan Commands

[](#️-artisan-commands)

#### `make:action`

[](#makeaction)

Quickly generates action classes in your Laravel application:

```
php artisan make:action CreateUserAction
```

This creates a clean action class at `app/Actions/CreateUserAction.php`:

```
