Download the PHP package jand3v/laravel-opinionated-essentials without Composer
On this page you can find all versions of the php package jand3v/laravel-opinionated-essentials. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-opinionated-essentials
Laravel Opinionated Essentials
Opinionated essentials for Laravel applications. Applies sensible framework defaults automatically and provides generators for common patterns.
Installation
The service provider is auto-discovered — no manual registration required.
Configuration
Publish the config file to adjust or disable individual defaults:
This creates config/opinionated-essentials.php in your application. Every default can be toggled via environment variables.
Opinionated Defaults
The following behaviors are applied automatically when the package is installed:
| Behavior | Config key | Env variable | Default |
|---|---|---|---|
| Eloquent lazy-loading prevention (non-production) | models.prevent_lazy_loading |
OPINIONATED_ESSENTIALS_PREVENT_LAZY_LOADING |
true |
| Carbon immutable dates | dates.immutable |
OPINIONATED_ESSENTIALS_IMMUTABLE_DATES |
true |
| Secure password rules in production | passwords.secure |
OPINIONATED_ESSENTIALS_SECURE_PASSWORDS |
true |
| Prohibit destructive DB commands in production | database.prevent-destruction |
OPINIONATED_ESSENTIALS_PREVENT_DB_DESTRUCTION |
true |
To disable a default, set the env variable to false or update config/opinionated-essentials.php.
Lazy Loading Prevention
Outside of production, accessing an unloaded Eloquent relationship throws a LazyLoadingViolationException, forcing eager loading and preventing N+1 queries:
Immutable Dates
All date instances returned by Eloquent are CarbonImmutable, preventing accidental mutation:
Secure Passwords (production only)
In production, Password::defaults() requires a minimum of 12 characters, mixed case, letters, numbers, symbols, and checks the password against the HaveIBeenPwned database:
In non-production environments Password::default() returns null (no extra constraints), making registration easy during development.
Prohibit Destructive Commands (production only)
DB::prohibitDestructiveCommands(true) is called in production, preventing migrate:fresh, migrate:reset, and db:wipe from running accidentally.
Generators
make:action
Creates a new Action class in app/Actions:
Generates app/Actions/PlaceOrderAction.php:
The
Actionsuffix is added automatically. PassingPlaceOrderActionproduces the same result — no double suffix.
--dto option
Pass --dto to generate an accompanying DTO and wire it into execute():
Generates both app/Actions/PlaceOrderAction.php and app/DTOs/PlaceOrderData.php:
make:dto
Creates a standalone DTO in app/DTOs without an Action:
Generates app/DTOs/PlaceOrderData.php (same structure as above). The Data suffix is added automatically — passing PlaceOrderData produces the same result.
DTOs and MapsFromArray
Every generated DTO uses the MapsFromArray trait, which maps an array (e.g. from $request->validated()) to constructor properties.
Defining a DTO
Creating instances
From a controller with a validated form request:
Or from any array:
Mapping resolution order
For each constructor parameter, the trait resolves the value in this order:
#[MapFrom('key')]— explicit array key (highest priority).- Exact camelCase name — e.g.
customerNamematches array keycustomerName. - snake_case fallback — e.g.
customerNamealso matchescustomer_name. - Default value or nullable — uses the parameter's default, or
nullif nullable. InvalidArgumentException— thrown when a required key is missing.
Testing
License
The MIT License (MIT). See LICENSE for details.