← Back to PHP Course | Chapter 15: Web Development | Lesson 3 of 12

PHP Laravel Introduction

What is Laravel?

Laravel is the most widely adopted PHP framework, built around the MVC pattern and known for prioritizing developer productivity through expressive syntax and a rich set of built-in tools.

Example: What is Laravel?

php
<?php
echo "Laravel: MVC-based, developer-friendly PHP framework";
?>

Basic Routing

Laravel's router maps incoming URLs to specific controller methods or inline closures in a single, readable routes file, keeping your application's URL structure easy to see at a glance.

Example: Basic Routing

php
<?php
// routes/web.php:
// Route::get('/users/{id}', [UserController::class, 'show']);
echo "Maps a URL pattern to a controller method";
?>

Blade Templating

Blade, Laravel's templating engine, compiles familiar-looking template syntax (like @if and @foreach) down into plain, cached PHP, giving you clean templates without sacrificing performance.

Example: Blade Templating

php
<?php
// Blade template syntax (compiles to plain PHP):
// @if($isAdmin) <p>Admin</p> @endif
echo "@if and @foreach compile down to cached plain PHP";
?>

Eloquent ORM

Eloquent is Laravel's ActiveRecord-style ORM, letting you query and manipulate database rows as PHP objects (like User::find(1)->save()) instead of writing raw SQL for common operations.

Example: Eloquent ORM

php
<?php
// $user = User::find(1);
// $user->name = "Alice";
// $user->save();
echo "Query and manipulate rows as PHP objects instead of raw SQL";
?>

Artisan CLI Commands

Artisan is Laravel's command-line tool, used to scaffold new controllers, models, and migrations in seconds and to run maintenance tasks like clearing caches or running the test suite.

Example: Artisan CLI Commands

php
<?php
// Run in terminal: php artisan make:controller UserController
echo "Artisan scaffolds controllers, models, and migrations";
?>

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.