Artisan — CLI Laravel 12
Interface CLI pour automatiser le développement Laravel.
🚀 Commandes essentielles
# Démarrage
php artisan serve
php artisan list
php artisan help make:model
# Cache production
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Vider caches
php artisan optimize:clear🏗️ Génération de code
Models
php artisan make:model User # simple
php artisan make:model User -mf # + migration + factory
php artisan make:model User -a # + API controllerControllers
php artisan make:controller UserController
php artisan make:controller PostController --resource
php artisan make:controller API/PostController --apiMigrations & Seeders
php artisan make:migration create_users_table
php artisan make:migration add_avatar_to_users_table --table=users
php artisan make:seeder UserSeeder
php artisan make:factory UserFactory --model=User🗄️ Base de données
# Migrations
php artisan migrate
php artisan migrate --force # production
php artisan migrate:rollback
php artisan migrate:rollback --step=3
php artisan migrate:refresh
php artisan migrate:fresh --seed
# Seeders
php artisan db:seed
php artisan db:seed --class=UserSeeder🎯 Tinker
php artisan tinker
>>> User::factory()->count(10)->create();
>>> User::where('active', true)->get();
>>> $user = User::find(1);
>>> $user->update(['name' => 'Updated']);🔧 Maintenance
# Mode maintenance
php artisan down
php artisan down --message="Update in progress"
php artisan up
# Optimisation
php artisan optimize
php artisan config:cache
php artisan route:cache🧪 Tests
php artisan test
php artisan test --coverage
php artisan test --testsuite=Feature
php artisan test tests/Feature/UserTest.php📦 Packages
# Installation et configuration
composer require spatie/laravel-permission
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
php artisan package:discover🔍 Debug
# Routes et configuration
php artisan route:list
php artisan route:list --name=users
php artisan config:show
php artisan about🛠️ Commandes personnalisées
# Créer une commande
php artisan make:command SendEmailsCommand// app/Console/Commands/SendEmailsCommand.php
class SendEmailsCommand extends Command
{
protected $signature = 'emails:send {user}';
protected $description = 'Send emails to a user';
public function handle(): int
{
$userId = $this->argument('user');
$this->info("Sending emails to user {$userId}...");
// Logique métier
$this->info('Emails sent successfully!');
return 0;
}
}# Exécution
php artisan emails:send 123
php artisan emails:send 123 --force --queue📋 Commandes utiles
# Assets
npm run dev
npm run build
php artisan vendor:publish --tag=public
# Scheduler
php artisan schedule:run
php artisan schedule:list
# Logs
tail -f storage/logs/laravel.logL’assistant qui code à ta place