Laravel Cheat Sheet
A searchable, printable Laravel reference — Artisan, routing, Eloquent, the query builder, migrations, Blade, validation and collections. Free.
Artisan CLI
14php artisan serve
php artisan make:model Post -mcr
php artisan make:controller PostController
php artisan make:migration create_posts_table
php artisan migrate
php artisan migrate:fresh --seed
php artisan db:seed
php artisan tinker
php artisan route:list
php artisan optimize
php artisan queue:work
php artisan schedule:work
php artisan storage:link
php artisan key:generate
Routing
13Route::get('/users', [UserController::class, 'index'])
Route::post('/users', [UserController::class, 'store'])
Route::put('/users/{user}', [UserController::class, 'update'])
Route::patch('/users/{user}', [UserController::class, 'update'])
Route::delete('/users/{user}', [UserController::class, 'destroy'])
Route::get('/users/{id}', $fn)
Route::get('/users/{id?}', $fn)
Route::get('/profile', $fn)->name('profile')
Route::get('/admin', $fn)->middleware('auth')
Route::resource('posts', PostController::class)
Route::prefix('admin')->group(function () {})
Route::controller(PostController::class)->group($fn)
Route::fallback($fn)
Controllers
10php artisan make:controller PostController --resource
public function __invoke(Request $request)
public function index() {}
public function store(Request $request) {}
public function show(Post $post) {}
public function __construct(PostService $svc) {}
return view('posts.index', ['posts' => $posts])
return response()->json($data)
return redirect()->route('posts.index')
return back()
Eloquent ORM
14Post::all()
Post::find($id)
Post::where('active', true)->first()
Post::create(['title' => 'Hi'])
$post->update(['title' => 'Edited'])
$post->delete()
Post::firstOrCreate(['slug' => $slug])
Post::updateOrCreate($attrs, $values)
Post::with('author')->get()
public function comments() { return $this->hasMany(Comment::class); }
public function author() { return $this->belongsTo(User::class); }
protected $fillable = ['title', 'body'];
protected function casts(): array { return ['published_at' => 'datetime']; }
Post::onlyTrashed()->restore()
Query builder
13DB::table('users')->get()
DB::table('users')->where('votes', '>', 100)->get()
DB::table('users')->join('posts', 'users.id', '=', 'posts.user_id')
DB::table('users')->orderBy('name')->get()
DB::table('orders')->groupBy('status')->get()
DB::table('users')->select('name', 'email')->get()
DB::table('users')->insert(['name' => 'Sam'])
DB::table('users')->where('id', 1)->update(['votes' => 1])
DB::table('users')->pluck('email')
DB::table('users')->count()
DB::table('users')->where('id', 1)->exists()
DB::table('users')->paginate(15)
DB::table('users')->chunk(100, $fn)
Migrations & schema
12Schema::create('posts', function (Blueprint $table) {})
$table->id()
$table->string('title')
$table->integer('votes')
$table->boolean('active')
$table->timestamps()
$table->foreignId('user_id')->constrained()
$table->string('note')->nullable()
$table->boolean('active')->default(true)
$table->index('slug')
$table->unique('email')
$table->dropColumn('votes')
Blade templates
14@if ($ok) ... @elseif ($x) ... @else ... @endif
@foreach ($posts as $post) ... @endforeach
@forelse ($posts as $post) ... @empty ... @endforelse
{{ $variable }}
{!! $html !!}
@extends('layouts.app')
@section('content') ... @endsection
@yield('content')
@include('partials.nav')
<x-alert type="error" />
@csrf
@auth ... @endauth
@can('update', $post) ... @endcan
{{ $loop->index }}
Validation
12$request->validate(['title' => 'required'])
'email' => 'required|email'
'name' => 'required|max:255'
'email' => 'unique:users,email'
'age' => 'nullable|integer|min:18'
'role' => ['required', Rule::in(['admin', 'user'])]
php artisan make:request StorePostRequest
public function rules(): array { return [...]; }
public function authorize(): bool { return true; }
public function messages(): array { return [...]; }
$validator = Validator::make($data, $rules)
$request->validated()
Requests & responses
10request()->input('name')
request()->query('page')
request()->all()
request()->only(['name', 'email'])
request()->has('name')
response()->json(['ok' => true])
redirect()->route('home')->with('status', 'Saved')
back()->withInput()
abort(404)
abort_if($user->banned, 403)
Collections
13$collection->map(fn ($x) => $x * 2)
$collection->filter(fn ($x) => $x > 0)
$collection->each(fn ($x) => $x->save())
$collection->pluck('name')
$collection->reduce(fn ($c, $x) => $c + $x, 0)
$collection->sortBy('created_at')
$collection->groupBy('status')
$collection->where('active', true)
$collection->first()
$collection->contains('name', 'Sam')
$collection->sum('price')
$collection->flatten()
$collection->toArray()
Auth & middleware
11Auth::user()
Auth::check()
Auth::id()
Auth::login($user)
Auth::logout()
auth()->user()
Route::get('/home', $fn)->middleware('auth')
Gate::allows('update', $post)
$user->can('update', $post)
php artisan make:policy PostPolicy --model=Post
php artisan make:middleware EnsureTokenIsValid
Helpers & misc
12config('app.name')
env('APP_DEBUG', false)
route('posts.show', $post)
url('/dashboard')
asset('css/app.css')
old('email')
now()->addDays(7)
Str::slug('My Title')
collect([1, 2, 3])->sum()
cache()->remember('key', 60, $fn)
dd($value)
Storage::put('file.txt', $contents)
No entry matches “:q”.
About Laravel Cheat Sheet
This Laravel cheat sheet condenses the framework surface you touch daily: Artisan CLI, routing, controllers, Eloquent ORM, the query builder, migrations and schema, Blade templates, validation, requests and responses, collections, auth and middleware, and helpers.
Laravel has an expressive but wide API — the exact Eloquent relationship signature, a migration column modifier, a validation rule name, a collection method — and each row here shows the real call with a one-line description, so the sheet reads like the framework in shorthand.
It is free and rendered entirely in your browser. Filter every snippet live with the search box, jump between sections from the sticky table of contents, copy code with one click and print the sheet for a framework reference while you build.
How to use Laravel Cheat Sheet
- Skim the twelve sections, from Artisan CLI and Routing through Eloquent ORM to Helpers & misc.
- Search for a term like migration, hasMany or validate to filter the sheet live.
- Jump to a section such as Blade templates or Collections via the sticky sidebar.
- Click a snippet or its copy icon to copy the PHP into your project.
- Print the sheet for an offline Laravel reference.