承接 nunomaduro/essentials 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nunomaduro/essentials

Composer 安装命令:

composer require nunomaduro/essentials

包简介

Just better defaults for your Laravel projects.

README 文档

README

Logo for essentials

Essentials

Build Status Total Downloads Latest Stable Version License YouTube Channel Subscribers

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.

Installation

⚡️ Get started by requiring the package using Composer:

composer require nunomaduro/essentials

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

✅ 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

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

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

Uses CarbonImmutable instead of mutable date objects across your app.

Why: Prevents unexpected date mutations and improves predictability.

🔒 Force HTTPS

Forces all generated URLs to use https://.

Why: Ensures all traffic uses secure connections by default.

🛑 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

Configures Laravel Vite to preload assets more aggressively.

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

🔄 Prevent Stray Requests

Configures Laravel Http Facade to prevent stray requests.

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

😴 Fake Sleep

Configures Laravel Sleep Facade to be faked.

Why: Avoid unexpected sleep during testing cases.

🏗️ Artisan Commands

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:

  • "declare_strict_types" - Enforces strict types in all files.
  • "final_class" - Enforces final classes by default.
  • "ordered_class_elements" - Orders class elements by visibility and type.
  • "strict_comparison" - Enforces strict comparison in all files.
  • and more...
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:

  • "deadCode" - Removes dead code from your codebase.
  • "codeQuality" - Improves code quality by applying best practices.
  • "typeDeclarations" - Adds type declarations to your codebase.
  • "privatization" - Privatizes class properties and methods where possible.
  • "earlyReturn" - Enforces early return statements in your codebase.
  • "strictBooleans" - Enforces strict boolean checks in your codebase.
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.

Configuration

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

Roadmap

  • Better defaults before each test case
  • Better Pint configuration by default
  • General cleanup of the skeleton
  • Additional configurables for common Laravel patterns

License

Essentials was created by Nuno Maduro under the MIT license.

nunomaduro/essentials 适用场景与选型建议

nunomaduro/essentials 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 541.64k 次下载、GitHub Stars 达 1.21k, 最近一次更新时间为 2025 年 04 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「package」 「php」 「laravel」 「essentials」 「laravel-essentials」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nunomaduro/essentials 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nunomaduro/essentials 我们能提供哪些服务?
定制开发 / 二次开发

基于 nunomaduro/essentials 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 541.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1214
  • 点击次数: 19
  • 依赖项目数: 67
  • 推荐数: 0

GitHub 信息

  • Stars: 1214
  • Watchers: 14
  • Forks: 75
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-11