Package Data | |
---|---|
Maintainer Username: | nunomaduro |
Maintainer Contact: | enunomaduro@gmail.com (Nuno Maduro) |
Package Create Date: | 2025-04-11 |
Package Last Update: | 2025-06-04 |
Home Page: | https://nunomaduro.com/sponsorships |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-07-05 03:00:04 |
Package Statistics | |
---|---|
Total Downloads: | 13,527 |
Monthly Downloads: | 9,924 |
Daily Downloads: | 293 |
Total Stars: | 747 |
Total Watchers: | 11 |
Total Forks: | 46 |
Total Open Issues: | 8 |
Essentials provide better defaults for your Laravel applications including strict models, automatically eagerly loaded relationships, immutable dates, and more!
Requires PHP 8.3+, Laravel 11+.
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.
⚡️ Get started by requiring the package using Composer:
composer require nunomaduro/essentials:^0.1
All features are optional and configurable in config/essentials.php
.
Improves how Eloquent handles undefined attributes, lazy loading, and invalid assignments.
Why: Avoids subtle bugs and makes model behavior easier to reason about.
Automatically eager loads relationships defined in the model's $with
property.
Why: Reduces N+1 query issues and improves performance without needing with()
everywhere.
Disables Laravel's mass assignment protection globally (opt-in).
Why: Useful in trusted or local environments where you want to skip defining $fillable
.
Uses CarbonImmutable
instead of mutable date objects across your app.
Why: Prevents unexpected date mutations and improves predictability.
Forces all generated URLs to use https://
.
Why: Ensures all traffic uses secure connections by default.
Blocks potentially destructive Artisan commands in production (e.g., migrate:fresh
).
Why: Prevents accidental data loss and adds a safety net in sensitive environments.
Configures Laravel Vite to preload assets more aggressively.
Why: Improves front-end load times and user experience.
Configures Laravel Http Facade to prevent stray requests.
Why: Ensure every HTTP calls during tests have been explicitly faked.
Configures Laravel Sleep Facade to be faked.
Why: Avoid unexpected sleep during testing cases.
make:action
Quickly generates action classes in your Laravel application:
php artisan make:action CreateUserAction
This creates a clean action class at app/Actions/CreateUserAction.php
:
<?php
declare(strict_types=1);
namespace App\Actions;
final readonly class CreateUserAction
{
/**
* Execute the action.
*/
public function handle(): void
{
DB::transaction(function (): void {
//
});
}
}
Actions help organize business logic in dedicated classes, promoting single responsibility and cleaner controllers.
essentials:pint
Laravel Pint is included by default in every Laravel project and is a great tool to keep your code clean and consistent. But it is configured very minimally by default. This command will publish a configuration file for Pint that includes the following:
php artisan essentials:pint {--force} {--backup}
Options:
--force
- Overwrites the existing configuration file without asking for confirmation.--backup
- Creates a backup of the existing configuration file.essentials:rector
Rector is a powerful tool for refactoring and improving your codebase. This command will publish a configuration file for Rector that includes the following:
php artisan essentials:rector {--force} {--backup}
Options:
--force
- Overwrites the existing configuration file without asking for confirmation.--backup
- Creates a backup of the existing configuration file.All features are configurable through the essentials.php
config file. By default, most features are enabled, but you can disable any feature by setting its configuration value to false
:
// config/essentials.php
return [
NunoMaduro\Essentials\Configurables\ShouldBeStrict::class => true,
NunoMaduro\Essentials\Configurables\Unguard::class => false,
// other configurables...
];
You may also publish the stubs used by this package:
php artisan vendor:publish --tag=essentials-stubs
Essentials was created by Nuno Maduro under the MIT license.