Master Laravel Framework with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.
Eloquent is Laravel's built-in Active Record ORM. Each database table has a corresponding Model class used to interact with that table. It provides an expressive syntax for queries:$users = User::where('active', true)->get();
In the parent model, define a method returning hasMany():public function posts() { return $this->hasMany(Post::class); }
In the child model, define the inverse with belongsTo():public function user() { return $this->belongsTo(User::class); }
Eager loading solves the N+1 query problem by loading relationships upfront:$books = Book::with('author')->get();
Without it, accessing a relationship in a loop triggers a separate query per iteration, causing performance issues.
Use the Artisan command:php artisan make:model Post -m
The -m flag generates a migration file alongside the model. You can also add -f for a factory and -s for a seeder.
Accessors transform attribute values when reading:protected function firstName(): Attribute { return Attribute::make(get: fn($value) => ucfirst($value)); }
Mutators transform values when setting:set: fn($value) => strtolower($value)
Blade is Laravel's templating engine. It provides convenient shortcuts for PHP control structures and template inheritance:{{ $var }} — escaped output@if, @foreach — control directives@extends, @section, @yield — layout inheritance
You can pass data in several ways:return view('profile', ['user' => $user]);return view('profile')->with('user', $user);return view('profile', compact('user'));All make $user available in the template.
{{ $var }} applies htmlspecialchars to escape output, preventing XSS attacks.{!! $var !!} outputs raw, unescaped HTML. Only use {!! !!} when you trust the content completely.
Use Artisan:php artisan make:component Alert
This creates a class at app/View/Components/Alert.php and a Blade file at resources/views/components/alert.blade.php. Use it with:<x-alert type="error" :message="$msg" />
Routes are defined in routes/web.php or routes/api.php:Route::get('/welcome', function () { return view('welcome'); });
You can also point to a controller:Route::get('/users', [UserController::class, 'index']);
Route parameters capture segments of the URI:
Required: Route::get('/user/{id}', ...)
Optional: Route::get('/user/{name?}', ...)
Parameters are passed as arguments to the closure or controller method.
Laravel can automatically inject model instances matching route parameters:Route::get('/posts/{post}', function (Post $post) { return $post; });
If the type-hinted variable matches the parameter name, Laravel resolves it by primary key automatically. Use getRouteKeyName() to customize.
Flashcards
Flip to reveal
Focus Mode
Spaced repetition
Multiple Choice
Test your knowledge
Type Answer
Active recall
Learn Mode
Multi-round mastery
Match Game
Memory challenge