composer.json and can be executed using composer run <script-name>.
User-Defined Scripts
These scripts are intended for manual execution during development and deployment workflows.setup
Sets up a fresh Laravel application by installing dependencies, configuring environment, and building assets.What it does
What it does
Executes the following steps in sequence:
composer install- Installs all PHP dependencies- Copies
.env.exampleto.envif it doesn’t exist php artisan key:generate- Generates application encryption keyphp artisan migrate --force- Runs database migrationsnpm install- Installs JavaScript dependenciesnpm run build- Builds frontend assets
This script is perfect for setting up your application after cloning the repository for the first time.
dev
Starts the development environment with all necessary services running concurrently.What it does
What it does
Launches four concurrent processes with color-coded output:All processes will be terminated together when you stop the script (Ctrl+C).
- Server (blue: #93c5fd) -
php artisan serve- Local development server - Queue (purple: #c4b5fd) -
php artisan queue:listen --tries=1 --timeout=0- Queue worker - Logs (pink: #fb7185) -
php artisan pail --timeout=0- Real-time log viewer - Vite (orange: #fdba74) -
npm run dev- Asset bundler with hot reload
Uses
npx concurrently to run all processes simultaneously. Process timeouts are disabled for long-running development sessions.This is the recommended way to start your development environment as it provides everything you need in a single command.
test
Runs the application’s test suite with a clean configuration.What it does
What it does
php artisan config:clear --ansi- Clears the configuration cachephp artisan test- Runs all tests using PHPUnit/Pest
Clearing the config cache ensures tests run with fresh configuration values.
Composer Hook Scripts
These scripts are automatically executed by Composer during specific lifecycle events. You typically don’t need to run these manually.post-autoload-dump
Executed automatically after Composer regenerates the autoload files.What it does
What it does
Illuminate\Foundation\ComposerScripts::postAutoloadDump- Framework bootstrapphp artisan package:discover --ansi- Discovers package service providers
This ensures Laravel packages are automatically registered when you install or update dependencies.
post-update-cmd
Executed automatically aftercomposer update completes.
What it does
What it does
php artisan vendor:publish --tag=laravel-assets --ansi --forcePublishes Laravel framework assets to your application, ensuring you have the latest versions after updates.post-root-package-install
Executed automatically when you first install the application usingcomposer create-project.
What it does
What it does
Creates a
.env file from .env.example if one doesn’t exist.This ensures your application has an environment configuration file immediately after installation.
post-create-project-cmd
Executed automatically after creating a new project withcomposer create-project.
What it does
What it does
php artisan key:generate --ansi- Generates a unique application key- Creates
database/database.sqliteif it doesn’t exist php artisan migrate --graceful --ansi- Runs initial database migrations
The
--graceful flag allows migrations to fail silently, which is useful when SQLite database doesn’t exist.pre-package-uninstall
Executed automatically before a package is uninstalled.What it does
What it does
Illuminate\Foundation\ComposerScripts::prePackageUninstallPerforms cleanup tasks before removing a package, ensuring proper deregistration of package service providers.Quick Reference
Manual Scripts
| Script | Command | Purpose |
|---|---|---|
setup | composer run setup | Complete application setup |
dev | composer run dev | Start development environment |
test | composer run test | Run test suite |
Automatic Hook Scripts
| Hook | Triggered By | Purpose |
|---|---|---|
post-autoload-dump | composer dump-autoload | Register packages |
post-update-cmd | composer update | Publish framework assets |
post-root-package-install | composer create-project | Create .env file |
post-create-project-cmd | composer create-project | Initialize new project |
pre-package-uninstall | composer remove | Clean up before uninstall |
Examples
Setting up a new development environment
Running tests before deployment
Manual package discovery
All scripts respect Composer’s process timeout settings. The
dev script explicitly disables timeouts for long-running processes.Related Configuration
The scripts reference several configuration files:- composer.json - Script definitions
- .env - Environment configuration
- package.json - NPM scripts and dependencies
- phpunit.xml - Test configuration
- vite.config.js - Asset bundler configuration
You can add your own custom scripts to
composer.json under the scripts section. Follow the same pattern as the existing scripts.