170 cards
Laravel routes are defined in routes/web.php for browser traffic or routes/api.php for stateless APIs. A route can return a view directly via a closure or point to a controller action such as Route::get('/users', [UserController::class, 'index']). Laravel maps each HTTP verb to a router method: get for reads, post for...
Eloquent is Laravel's Active Record ORM: every database table maps to a Model class that provides an expressive, chainable query interface. Generate a model and its migration together with php artisan make:model Post -m; the -f flag also creates a factory and -s a seeder. To insert, update, or delete records, use creat...
Migrations are Laravel's version control for database schemas. Generate one with php artisan make:migration create_posts_table, define schema changes in up(), and put the inverse in down(). Run with php artisan migrate, roll back with migrate:rollback, refresh with migrate:refresh (rollback plus re-run, keeping tables)...
Blade is Laravel's lightweight templating engine that augments HTML with shortcuts for PHP control flow, output escaping, and template inheritance. The double-brace syntax {{ $var }} applies htmlspecialchars to escape output and prevent XSS, while {!! $var !!} renders raw HTML, used only when you trust the source. Cont...
Laravel provides two complementary authorization layers: gates (closures) and policies (classes). Define gates in AuthServiceProvider with Gate::define('update-post', function (User $user, Post $post) { return $user->id === $post->user_id; }), then check with Gate::allows('update-post', $post) or @can('update-pos...
Artisan is Laravel's command-line interface, and a set of common commands covers most daily tasks: serve for the dev server, migrate, make:model, tinker (interactive REPL powered by PsySH), route:list, and cache:clear. Create your own commands with make:command SendEmails, set the $signature property, and put logic in...
Laravel's service container is the backbone of dependency injection. It resolves classes and their dependencies automatically, including all of Laravel's own components. Bind implementations with $this->app->bind(Interface::class, Implementation::class); use singleton() instead of bind() when the same instance sh...