This content originally appeared on DEV Community and was authored by Roberto Celano
Introduzione | Introduction
Italiano: Questo articolo è disponibile sia in italiano che in inglese. Scrolla verso il basso per la versione in inglese.
English: This article is available in both Italian and English. Scroll down for the English version.
I 10 comandi Artisan più utili in Laravel
Laravel offre una CLI potentissima: Artisan.
Con pochi comandi puoi generare codice, gestire il database e molto altro.
Ecco una selezione dei 10 comandi che uso più spesso e che ti consiglio di imparare subito.
1⃣ php artisan route:list
Mostra tutte le rotte definite nella tua applicazione.
Utilissimo per debug o quando ereditate un progetto.
2⃣ php artisan make:model Nome -mcr
Crea un model con:
-
-m
: migration -
-c
: controller -
-r
: resource controller
php artisan make:model Post -mcr
3⃣ php artisan migrate
Applica tutte le migrazioni al database.
4⃣ php artisan migrate:fresh --seed
Attenzione! Cancella e ricrea tutto il database, poi esegue i seeder.
Perfetto in sviluppo.Non adatto in produzione.
5⃣ php artisan db:seed
Esegue solo i seeder definiti in DatabaseSeeder.php
(o altri).
6⃣ php artisan tinker
Avvia una console interattiva dove puoi testare comandi Laravel, fare query sui modelli e molto altro.
Perfetto per debug e prove rapide.
7⃣ php artisan make:request NomeRequest
Crea una classe di validazione personalizzata.
Ottimo per validare le richieste POST
o PUT
in modo ordinato.
8⃣ php artisan config:cache
Ricompila i file di configurazione e migliora le performance.
Utile dopo modifiche nei file .env
o in config/
.
9⃣ php artisan storage:link
Crea il link simbolico necessario per accedere ai file pubblici caricati (es. immagini).
Assicura che i file in storage/app/public
siano accessibili da public/storage
.
php artisan make:middleware NomeMiddleware
Crea un middleware.
Perfetto per logica personalizzata come permessi, ruoli, filtri IP, ecc.
Conclusione
Imparare a usare Artisan ti velocizza il lavoro e ti rende più produttivo.
Non serve ricordare tutto a memoria, ma sapere cosa puoi fare è già metà dell’opera.
10 Artisan Commands Every Laravel Developer Should Know
Laravel offers a powerful CLI: Artisan.
With just a few commands, you can generate code, manage the DB, and speed up your workflow.
Here’s a selection of the 10 Artisan commands I use most often — and that you should know as well.
1⃣ php artisan route:list
Displays all routes defined in your application.
Extremely useful for debugging or understanding legacy projects.
2⃣ php artisan make:model Name -mcr
Creates a model with:
-
-m
: migration -
-c
: controller -
-r
: resource controller
php artisan make:model Post -mcr
3⃣ php artisan migrate
Applies all migrations to the database.
4⃣ php artisan migrate:fresh --seed
Warning! This command drops all tables, re-runs all migrations,and then runs the seeders.
Great for development, not for production.
5⃣ php artisan db:seed
Runs only the seeders defined in DatabaseSeeder.php
(or other custom ones).
6⃣ php artisan tinker
Launches an interactive REPL where you can run Laravel commands, test model queries, or play with collections in real time.
7⃣ php artisan make:request CustomRequest
Generates a custom request validation class.
Perfect for cleanly validating POST
or PUT
inputs.
8⃣ php artisan config:cache
Rebuilds the configuration cache to boost performance.
Use it after changing .env
or config/*.php
files.
9⃣ php artisan storage:link
Creates the symbolic link from public/storage
to storage/app/public
,
allowing access to uploaded files via browser.
php artisan make:middleware ExampleMiddleware
Generates a new middleware class.
Ideal for handling custom logic like user roles, permissions, request filtering, etc.
Conclusion
Learning how to use Artisan makes your workflow faster and more efficient.
You don’t need to memorize everything — just knowing what exists gives you a big advantage.
Traduzione:
Questo articolo è stato tradotto con l’ausilio di strumenti di traduzione professionali.
Translation:
This article was translated with the help of professional translation tools.
This content originally appeared on DEV Community and was authored by Roberto Celano