shahabzebare/laravel-nova-turbo 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

shahabzebare/laravel-nova-turbo

Composer 安装命令:

composer require shahabzebare/laravel-nova-turbo

包简介

Turbocharge Laravel Nova by lazy loading resources. Dramatically improves performance for applications with 50+ resources.

README 文档

README

Latest Version on Packagist Tests Total Downloads License

🚀 Turbocharge Laravel Nova by lazy loading resources.

If you have 50+ resources, Nova can become slow because it loads and runs authorization checks for ALL resources on every page load. This package fixes that by only loading the resources needed for the current page.

The Problem

Nova's default behavior on every page load:

  • Registers all resources (e.g., 100 resources)
  • Runs authorizedToCreate() for each resource
  • Generates metadata for all resources

With Nova Turbo:

  • Only loads 1-5 resources per page (current resource + relationships)
  • Dramatically improves page load times

Benchmarks

Real-world performance comparison on a Nova installation with 100+ resources:

Metric Without Turbo With Turbo Improvement
Server Response Time 455.58 ms 186.00 ms 59% faster
Resources Loaded ~100 1-5 95% reduction
📊 Click to see benchmark screenshots

With Nova Turbo (186ms)

With Nova Turbo

Without Nova Turbo (455ms)

Without Nova Turbo

Installation

composer require shahabzebare/laravel-nova-turbo

Setup

Step 1: Add the trait to your NovaServiceProvider

<?php

namespace App\Providers;

use Laravel\Nova\NovaApplicationServiceProvider;
use Shahabzebare\NovaTurbo\Traits\TurboLoadsResources;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    use TurboLoadsResources;

    // ... rest of your provider
}

Step 2: Generate the cache

php artisan nova:turbo-cache

This creates a cache file at bootstrap/cache/nova-turbo.php.

Step 3 (Optional): Publish config

php artisan vendor:publish --tag=nova-turbo-config

Commands

# Generate/refresh cache
php artisan nova:turbo-cache

# Clear cache
php artisan nova:turbo-cache --clear

Configuration

// config/nova-turbo.php

return [
    // Skip lazy loading in local environment for development
    'auto_refresh_in_dev' => true,

    // Paths to scan for Nova resources
    'resource_paths' => [
        app_path('Nova'),
    ],

    // Auto-regenerate cache when Laravel's cache is cleared (e.g., during deployments)
    'regenerate_on_cache_clear' => true,
];

External Resources

If you have resources outside app/Nova (e.g., in modules), register them:

// In your AppServiceProvider or a module service provider
use Shahabzebare\NovaTurbo\NovaTurbo;

public function boot()
{
    NovaTurbo::resources([
        \Modules\Order\Nova\Order::class,
        \Modules\Customer\Nova\Customer::class,
    ]);
}

Then re-run php artisan nova:turbo-cache.

Deployment

The cache is automatically regenerated when you run php artisan cache:clear during deployments (enabled by default via regenerate_on_cache_clear).

If you prefer manual control, add to your deployment script:

php artisan nova:turbo-cache

Typical deployment order:

php artisan config:cache
php artisan route:cache
php artisan cache:clear          # Auto-regenerates turbo cache
# OR manually: php artisan nova:turbo-cache

To disable automatic regeneration:

NOVA_TURBO_REGENERATE_ON_CLEAR=false

How It Works

  1. The artisan command scans all resources and their relationship fields
  2. It builds a dependency map and caches it as a PHP array file (with version tracking)
  3. On page load, only the needed resources are registered
  4. The cached metadata is sent to the frontend to prevent JavaScript errors
  5. Cache is automatically invalidated when the package is updated (version mismatch)

Development Mode

By default, lazy loading is disabled in local environment (auto_refresh_in_dev = true). This means you can add/modify resources without running the cache command.

For production-like testing locally:

NOVA_TURBO_AUTO_REFRESH=false php artisan serve

License

MIT License. See LICENSE for details.

Credits

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固