liminfo

Laravel Reference

Free reference guide: Laravel Reference

29 results

About Laravel Reference

The Laravel Reference is a searchable cheat sheet covering the most-used syntax and patterns in the Laravel PHP framework. It is organized into six categories — Routing, Eloquent ORM, Middleware, Blade templates, Migrations, and Authentication — so developers can jump straight to the section they need without scrolling through long documentation pages.

Backend developers, full-stack engineers, and PHP students use this reference when building REST APIs, web applications, and admin panels with Laravel. The Eloquent section covers everything from basic queries like Model::all() and Model::where() to relationship definitions such as hasMany, belongsTo, and belongsToMany, while the Routing section includes RESTful resource routes, prefix groups, and HTTP verb methods.

The Authentication and Middleware sections address real-world concerns such as Auth::attempt(), Auth::user(), route-level middleware, throttle rate limiting, and policy-based authorization. The Blade category covers the templating directives developers use every day: conditional @if blocks, @foreach loops, layout inheritance via @extends/@section/@yield, and safe vs. unescaped output.

Key Features

  • Routing coverage: GET, POST, PUT, DELETE, resource routes, and prefix groups with real controller examples
  • Eloquent ORM: Model::find, where()->get(), create(), save(), and relationship methods (hasMany, belongsToMany)
  • Middleware syntax: make:middleware artisan command, auth guard, throttle rate limiting, and custom handle logic
  • Blade directives: {{ }}, {!! !!}, @if/@foreach, and full @extends/@section/@yield layout inheritance
  • Database migrations: make:migration, Schema::create with Blueprint column types, migrate, rollback, and fresh --seed
  • Auth facade: Auth::attempt(), Auth::user(), Auth::logout(), and policy generation via make:policy
  • Category filter to instantly narrow results to Routing, Eloquent, Middleware, Blade, Migration, or Auth
  • Instant search across syntax, descriptions, and code examples — no page reload required

Frequently Asked Questions

What does the Laravel Reference cover?

It covers six core areas of the Laravel framework: Routing (HTTP verbs, resource routes, route groups), Eloquent ORM (CRUD queries and relationships), Middleware (auth, throttle, custom handle), Blade templates (output, conditionals, loops, layout), Migrations (schema creation and execution), and Authentication (Auth facade, guards, and policies).

How do I define a RESTful resource route in Laravel?

Use Route::resource('photos', PhotoController::class). This single line automatically generates index, create, store, show, edit, update, and destroy routes mapped to the corresponding controller methods.

What is the difference between {{ }} and {!! !!} in Blade?

{{ $var }} escapes HTML entities to prevent XSS attacks, making it safe for user-supplied data. {!! $html !!} outputs raw unescaped HTML and should only be used when you trust the source, such as when rendering sanitized content from a WYSIWYG editor.

How does the .data AT> FLASH pattern work in Laravel migrations?

In Laravel migrations you define your schema with Schema::create() using a Blueprint callback. Column helpers like $table->string(), $table->integer(), and $table->timestamps() map directly to SQL column types. Run php artisan migrate to apply, php artisan migrate:rollback to undo, and php artisan migrate:fresh --seed to reset and re-seed the database.

How do I apply middleware to a specific route?

Chain ->middleware('auth') on the route definition: Route::get('/dashboard', [DashController::class, 'index'])->middleware('auth'). For multiple middleware use an array. You can also apply middleware to groups using Route::middleware([])->group().

What is the difference between hasMany and belongsToMany in Eloquent?

hasMany defines a one-to-many relationship (e.g., a User hasMany Posts), meaning the foreign key lives in the related table. belongsToMany defines a many-to-many relationship (e.g., a User belongsToMany Roles) using a pivot table that stores both foreign keys.

How does Auth::attempt() work?

Auth::attempt(['email' => $email, 'password' => $password]) looks up the user by email, hashes the submitted password using Laravel's hasher, and compares it with the stored hash. If they match, the user is logged in and a session is created. It returns true on success and false on failure.

Can I use this reference offline?

Once the page has loaded in your browser, all reference data is stored in memory and can be searched and filtered without an internet connection. No requests are made to any server while you use the reference.