Laravel cheat sheet

A scannable Laravel reference: 16 short snippets across 9 topics, each linking back to the lesson it came from.

At a glance

TopicWhat it covers
Installation and routingLaravel is a Composer package, so a project is a directory with a manifest and an artisan console at its root. PHP 8.2lesson
Migrations and validationVersioned schema changes you can roll back, and rules that keep unvalidated input away from the databaselesson
Authentication and authorizationThrottle login by the submitted identifier as well as the IP, otherwise one attacker with many addresses freelylesson
Queues, jobs and scheduled tasksRun workers under Supervisor or Horizon with --max-time so a leaked resource is reclaimed. One long-running workerlesson
Building APIs with SanctumClients parse errors more reliably when the shape never changes. Decide on one envelope - error.code, error.messagelesson
File storage and uploadsPHP's upload_max_filesize and post_max_size cap uploads before Laravel sees them. When a request silently arrives withlesson
Caching, performance and debuggingCache stores and tags, remembering values correctly, route and config caching, hunting N+1 queries, Telescope, andlesson
Deployment and production hardeningEnvironment configuration, config caching done safely, Supervisor-managed queues, zero-downtime releases, health checkslesson
Next steps: Livewire, Inertia and package developmentChoosing between Livewire and an Inertia SPA, Livewire component basics, Inertia page props, and packaging a reusablelesson

Quick snippets

Installation and routing

Installation and the Artisan workflow

# create a project with Composer
composer create-project laravel/laravel example-app
cd example-app

php artisan serve          # http://127.0.0.1:8000
php artisan about          # versions, drivers and environment summary
php artisan route:list     # every registered route and its action
php artisan migrate        # apply pending database migrations
php artisan tinker         # REPL with the framework booted

Full lesson: Installation and routing →

Migrations and validation

Migrations

php artisan make:migration create_posts_table --create=posts
php artisan migrate
php artisan migrate:rollback --step=1
php artisan migrate:status

Validation and form requests

php artisan make:request StorePostRequest

Validation and form requests

public function store(StorePostRequest $request)
{
    // runs only if authorize() passed and the rules passed
    return Post::create($request->validated());
}

Full lesson: Migrations and validation →

Authentication and authorization

Verification, reset and rate limits

class User extends Authenticatable implements MustVerifyEmail
{
    use HasFactory, Notifiable;
}

Route::get('/billing', BillingController::class)
    ->middleware(['auth', 'verified', 'can:viewBilling,App\Models\Account']);

// throttling auth endpoints
RateLimiter::for('login', fn (Request $request) =>
    Limit::perMinute(5)->by($request->input('email').'|'.$request->ip()));

Full lesson: Authentication and authorization →

Queues, jobs and scheduled tasks

Running the queues

php artisan queue:work redis --queue=high,default,mail --tries=5 --max-time=3600
php artisan queue:failed
php artisan queue:retry all
php artisan queue:monitor redis:default,redis:mail --max=1000
php artisan horizon        # supervisor, metrics and UI

Scheduled tasks

// routes/console.php (Laravel 11+)
Schedule::command('reports:daily')->dailyAt('02:00')->timezone('UTC');
Schedule::job(new RefreshCatalog)->hourly()->withoutOverlapping();
Schedule::call(fn () => Cache::forget('catalog'))->everyFiveMinutes()
    ->runInBackground()
    ->onOneServer()
    ->evenInMaintenanceMode();

// one cron entry drives everything
// * * * * * cd /var/www/app && php artisan schedule:run >> /dev/null 2>&1

Full lesson: Queues, jobs and scheduled tasks →

Building APIs with Sanctum

Resources and pagination

Route::middleware('throttle:api')->group(function () {
    Route::apiResource('books', BookController::class);
});

// per-endpoint limit
Route::post('/books', StoreBook::class)->middleware('throttle:20,1');

Full lesson: Building APIs with Sanctum →

File storage and uploads

Validating uploads

$validated = $request->validate([
    'cover' => ['required', 'file', 'image', 'mimes:jpeg,png,webp', 'max:5120',
                'dimensions:min_width=400,min_height=300'],
    'attachment' => ['nullable', 'file', 'mimes:pdf', 'max:20480'],
]);

$path = $request->file('cover')->store('covers', 's3');

// move the work off the request thread
ProcessCoverImage::dispatch($book, $path)->onQueue('images');

Full lesson: File storage and uploads →

Caching, performance and debugging

Finding the actual bottleneck

php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
php artisan optimize            # all of the above
php artisan optimize:clear      # and clear them

php artisan telescope:install && php artisan migrate
php artisan db:monitor --databases=mysql --max=100

Finding the actual bottleneck

// queue a slow side effect so the response does not wait
ProcessCover::dispatch($book);

// select only what the template needs
$books = Book::query()
    ->select(['id', 'title', 'author_id'])
    ->with('author:id,name')
    ->paginate(25);

Octane and long-running workers

composer require laravel/octane
php artisan octane:install --server=frankenphp
php artisan octane:start --workers=auto --max-requests=500

Full lesson: Caching, performance and debugging →

Deployment and production hardening

Configuration and caching

composer install --no-dev --optimize-autoloader --classmap-authoritative
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
php artisan queue:restart
php artisan horizon:terminate
php artisan storage:link

Zero-downtime releases

# atomic release with a symlink switch
releases/20260918120000/   <- new code, composer install, caches built
shared/.env  storage/  uploads/
current -> releases/20260918120000

# switch
ln -sfn releases/20260918120000 current
# then reload php-fpm so OPcache picks up the new paths

Zero-downtime releases

// a meaningful health endpoint
Route::get('/health', function () {
    DB::select('select 1');
    Cache::store('redis')->get('health-probe');
    return response()->json(['status' => 'ok', 'release' => config('app.release')]);
});

Full lesson: Deployment and production hardening →

Next steps: Livewire, Inertia and package development

Inertia page props and packaging

# scaffold a distributable package
composer require spatie/laravel-package-tools --dev
mkdir -p packages/laravel-metrics/src
cd packages/laravel-metrics && composer init

# in the package composer.json
# "extra": { "laravel": { "providers": ["Acme\\Metrics\\MetricsServiceProvider"] } }
# then: composer require acme/laravel-metrics

Full lesson: Next steps: Livewire, Inertia and package development →

FAQ

Is this Laravel cheat sheet free to use?
Yes. No sign-up and no tracking: the page is static, every example is on the page itself, and you can print it or save it as a one-page reference.
Where do the examples come from?
Every snippet is taken from the 9 lessons of the Laravel course on this site, and each section links back to the lesson it was pulled from.
How do I go deeper than a cheat sheet?
Open the full Laravel course — it carries the worked explanations, the edge cases and the exercises behind every line here.

Node.js PHP Java HTTP Go Rust

Last refreshed 2026-09-27.