The Dev Log › Tips & Cheat Codes
Laravel Artisan and Tinker Tricks That Save Me Time Every Day
By Jezer Niel Blanca, Full Stack Developer ·
·
6 min read
The Artisan commands, generator flags and Tinker habits I use constantly to move faster in Laravel, plus the safety rules I never break.
I spend a surprising amount of every working day in the terminal typing php artisan. Over the years I've collected a set of Artisan commands, flags and Tinker habits that save me minutes every hour, and those minutes add up fast. Most of them are built into Laravel already; they just aren't obvious until someone shows you. Here are the ones I reach for constantly, grouped by what they help with, plus a few safety rules I never break.
Set Yourself Up First
Before the tricks, two small things make everything else faster.
A Short Alias
Typing php artisan hundreds of times a day is a waste of keystrokes. Add an alias to your shell config:
alias pa="php artisan"
alias pat="php artisan test --compact"
alias tinker="php artisan tinker"
Now pa route:list and pat do exactly what you expect.
Know What's Available
When you forget a command or its options, Artisan tells you. php artisan list shows every command, php artisan list make narrows it to one namespace, and php artisan help migrate shows every flag for a single command. I use help far more than I search the web.
Generators That Do More Than You Think
Most developers know make:model, but not everyone uses its flags. One command can create the model plus everything around it:
php artisan make:model Invoice -mfsc --no-interaction
That gives you a migration (-m), factory (-f), seeder (-s) and controller (-c) in one go. Add -r for a resource controller, -R for form requests, or --policy for a policy. The --all flag creates the full set when you want everything.
A few other generators I use often:
php artisan make:request StoreInvoiceRequest for validation classes.
php artisan make:test InvoiceTest --pest for a Pest feature test.
php artisan make:class Services/InvoiceCalculator for a plain PHP class in the right place.
php artisan make:enum InvoiceStatus for a backed enum.
Customise the Stubs
If you always edit generated files the same way, publish the stubs with php artisan stub:publish. They land in a stubs folder in your project, and every future make: command uses your versions. It's a quiet way to enforce team conventions.
Inspecting Your App Without Opening Files
These commands answer questions that would otherwise mean digging through code:
php artisan about
php artisan route:list --except-vendor
php artisan route:list --path=api --method=POST
php artisan model:show Invoice
php artisan db:show
php artisan db:table invoices
php artisan config:show database
Here's what each is good for:
about summarises the environment, drivers, cache status and versions. It's the first thing I run on an unfamiliar project.
route:list with filters finds the exact route you need without scrolling through hundreds.
model:show lists a model's attributes, casts, relationships and observers in one view.
db:show and db:table show connection details, table sizes, columns and indexes.
config:show prints the resolved value of a config file, which is perfect for checking what .env actually produced.
Before you open five files to understand how something is wired, ask Artisan. It usually already knows.
Tinker Habits That Save Time
Tinker is a REPL with your whole application loaded. It's ideal for exploring data, trying out a query, or checking how a helper behaves.
$user = User::query()->where('email', 'someone@example.com')->first();
$user->invoices()->latest()->take(3)->get();
Str::of('Hello World')->slug();
now()->addWeekdays(5)->toDateString();
See the SQL Behind a Query
When a query isn't returning what you expect, look at the SQL it produces. toRawSql() shows the query with bindings filled in:
Invoice::query()
->where('status', 'overdue')
->whereDate('due_at', '<', now())
->toRawSql();
You can also chain ->dd() or ->dump() onto a query builder to print it without breaking the chain.
Build Test Data Quickly
Factories work inside Tinker too. make() builds models without saving them, which is great for checking accessors and casts safely:
$invoice = Invoice::factory()->make();
$invoice->total_formatted;
Only use create() in Tinker against your local database. That leads to the most important rule in this post.
Handy PsySH Commands
Tinker is built on PsySH, which adds its own helpers. ls lists variables in scope, doc shows documentation for a function or method, and show prints the source code of a method. Typing show App\Models\Invoice::scopeOverdue is often faster than finding the file.
Database and Queue Shortcuts
For day-to-day database work these save the most time:
php artisan migrate:status shows which migrations have run.
php artisan migrate:rollback --step=1 undoes just the last batch.
php artisan migrate:fresh --seed rebuilds your local database from scratch.
php artisan db drops you straight into the database CLI using your app's credentials.
php artisan db:seed --class=InvoiceSeeder runs one seeder.
And for queues and scheduling:
php artisan queue:failed
php artisan queue:retry all
php artisan queue:monitor redis:default --max=100
php artisan schedule:list
php artisan schedule:test
schedule:list shows every scheduled task with its next run time, and schedule:test lets you pick one and run it immediately, which beats waiting for the cron.
Safety Rules I Never Break
Artisan is powerful, and some commands are destructive. These rules have kept me out of trouble:
- Never run
migrate:fresh or db:wipe outside local. They drop every table. Laravel asks for confirmation in production, but don't rely on that.
- Avoid Tinker writes in production. If data needs fixing, write a small command or migration that is reviewed, tested and repeatable.
- Use
--pretend first. php artisan migrate --pretend prints the SQL a migration would run without running it.
- Clear caches deliberately.
php artisan optimize:clear clears config, route, view and event caches in one command when something seems stale after a change.
Maintenance Mode With a Back Door
When you do need to take the app down briefly, php artisan down --secret="let-me-in" shows visitors the maintenance page but lets you bypass it by visiting /let-me-in once. php artisan up brings it back.
Wrapping up
A short alias, the right generator flags, the inspection commands, a few Tinker habits and some firm safety rules will make you noticeably faster in any Laravel project. Pick three commands from this post you don't use yet and make a point of using them this week until they stick. And if you want a Laravel team that works this way on your product, I'd love for you to build it with me and my team.
Tags: Laravel, Artisan, Tinker, Productivity