jpswade/laravel-best-practices
Installation Add the package via Composer:
composer require jpswade/laravel-best-practices
Publish the config (if needed):
php artisan vendor:publish --provider="Jpswade\LaravelBestPractices\BestPracticesServiceProvider"
Prerequisites
Ensure Laravel Boost is installed (this package extends its laravel-best-practices skill). Run:
composer require beberlei/laravel-boost
First Use Case Run the best-practices checks during development:
php artisan boost:check
Or integrate into your CI pipeline (e.g., GitHub Actions) to enforce standards pre-merge.
Enforcing Standards
boost:check to validate:
App\ prefix).app/Http/Controllers/ for controllers).PascalCase for classes, snake_case for migrations).BestPracticesServiceProvider:
// app/Providers/BestPracticesServiceProvider.php
public function register()
{
$this->app->make(\Jpswade\LaravelBestPractices\Rules\CustomRule::class);
}
Integration with Boost
laravel-best-practices:
// config/boost.php
'skills' => [
\Beberlei\Boost\Skills\LaravelBestPractices::class,
\Jpswade\LaravelBestPractices\Skills\ExtendedBestPractices::class,
],
config/laravel-best-practices.php:
'rules' => [
'namespaces' => true,
'controller_location' => false, // Disable if using custom structure
],
CI/CD Pipeline
# .github/workflows/laravel.yml
- name: Run Best Practices
run: php artisan boost:check --fail-on-violations
php artisan boost:check in a hook to catch issues early.README.md or a wiki.Rule Conflicts
config/laravel-best-practices.php.Performance Overhead
php artisan boost:check --path=app/Http/Controllers
False Positives
// app/Rules/CustomNamespaceRule.php
public function passes($file)
{
return str_starts_with($file, 'app/') && !str_contains($file, 'Exceptions/');
}
--verbose to see detailed rule explanations:
php artisan boost:check --verbose
php artisan boost:check --dry-run
// config/laravel-best-practices.php
'rules' => ['controller_location' => true, ...],
Custom Rules
Jpswade\LaravelBestPractices\Contracts\Rule:
namespace App\Rules;
use Jpswade\LaravelBestPractices\Contracts\Rule;
class CustomRule implements Rule
{
public function passes($file) { /* ... */ }
public function message() { return 'Custom rule message'; }
}
BestPracticesServiceProvider.Modifying Existing Rules
php artisan vendor:publish --tag="laravel-best-practices-config"
config/laravel-best-practices.php to adjust severity or thresholds.Excluding Files/Directories
.boostignore (similar to .gitignore) to skip files:
# .boostignore
app/Exceptions/
resources/views/cache/
--fix to auto-correct simple issues:
php artisan boost:check --fix
RULE_EXCEPTIONS.md file to justify disabled rules for future devs.How can I help you explore Laravel packages today?