My Best Practices for Laravel Nova Development in Business Applications

** (Last Updated: 2023-06-29) **

In this note, I'll share my personal list of essential tasks and best practices for coding in Laravel Nova specifically tailored for business applications. These practices will help you create scalable, efficient, and secure codebases. Keep in mind that this article will be continuously updated to provide you with even more valuable insights and recommendations.

1. Enable Lazy Loading Prevention

In AppServiceProvider.php

/**
 * Bootstrap any application services.
 */
public function boot(): void
{
    Model::preventLazyLoading(! app()->isProduction());
}

Reference: https://laravel.com/docs/10.x/eloquent#configuring-eloquent-strictness

2. Enable Action Events as Audit Trail

Reference: https://github.com/laravel/nova-issues/discussions/5646

3. Setup deploy scripts in Forge

cd /home/forge/yourproject
git pull origin $FORGE_SITE_BRANCH

$FORGE_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader

npm ci
npm run build

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
    $FORGE_PHP artisan env:decrypt --env=production --filename=.env --force
    $FORGE_PHP artisan migrate --force

    $FORGE_PHP artisan config:clear
    $FORGE_PHP artisan event:clear
    $FORGE_PHP artisan route:clear
    $FORGE_PHP artisan view:clear
    $FORGE_PHP artisan auth:clear-resets

    $FORGE_PHP artisan config:cache
    $FORGE_PHP artisan route:cache
    $FORGE_PHP artisan event:cache
    $FORGE_PHP artisan view:cache
fi

Reference: https://bootcamp.laravel.com/deploying#configuring-your-deploy-script Reference: https://gist.github.com/BenSampo/aa5f72584df79f679a7e603ace517c14

More to come!