Workflow / Format on commit
Format on commit
Use --staged in a pre-commit hook to format staged content without touching unstaged work.
--staged formats what you staged and re-stages it. Unstaged edits are never touched.
Terminal
vendor/bin/laravel-fmt --stagedThe hook
.git/hooks/pre-commit
#!/bin/sh
vendor/bin/laravel-fmt --stagedMake it executable with chmod +x .git/hooks/pre-commit. The same line works in .husky/pre-commit.
Partly staged files
If a file also has unstaged edits, the staged part is formatted and your working copy is left alone:
Terminal
~ app/Models/User.php
~ resources/views/nav.blade.php (re-staged; working tree kept, unstaged changes)
✓ 2 files formatted and re-stagedgit diff will show the formatting undone. Do not git add the file again.
Reformatting does not stop the commit. It stops only if a file fails to format.
lint-staged
package.json
{
"lint-staged": {
"*.php": "vendor/bin/laravel-fmt"
}
}lint-staged passes file paths, so ignored files get formatted too. The --staged hook does not.