Laravel
The Laravel MVC Framework
For full documentation visit laravel.com.
Over 10 Years | Multiple Projects | Preferred
Laravel is an open-source PHP web framework designed to simplify common development tasks like routing, authentication, and database manipulation through an expressive, elegant syntax. It acts as a full-stack or backend tool that lets you build scalable modern web applications efficiently.
Core Architecture: The MVC Pattern
Laravel strictly follows the Model-View-Controller (MVC) structural pattern:
-
Model: Manages data, databases, and structural logic (powered by Laravel's Eloquent ORM).
-
View: Handles presentation and user interfaces (powered by Laravel's Blade Templating system).
-
Controller: Serves as the intermediary brain containing business logic to process user requests.
Step-by-Step Practical Example
Below is a complete, real-world scenario mapping out how to build a basic user data route using Laravel components.
- 1. The Route
The route serves as the entry endpoint for an incoming HTTP request. This maps the URL pattern to a specific function.
<?php
// routes/web.php
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;
// When a user visits /user/5, trigger the show method in UserController
Route::get('/user/{id}', [UserController::class, 'show']);
- 2. The Model
The Eloquent Model acts as your direct interface to your underlying SQL tables without requiring manual SQL strings.
<?php
// app/Models/User.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
// Laravel automatically maps this to a database table named 'users'
}
- 3. The Controller
The controller intercepts parameters from the route, calls the Model to look up data from the database, and passes it to the view layer.
<?php
// app/Http/Controllers/UserController.php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\View\View;
class UserController extends Controller
{
public function show(string $id): View
{
// Fetch the user by ID or fail automatically (throws 404 error)
$user = User::findOrFail($id);
// Pass the user object into a Blade view template called 'profile'
return view('user.profile', ['user' => $user]);
}
}
- 4. The View
The view formats the presentation. Laravel's proprietary .blade.php files use simple helper syntax wrappers to cleanly echo variable strings.
<!-- resources/views/user/profile.blade.php -->
<!DOCTYPE html>
<html>
<head>
<title>User Profile</title>
</head>
<body>
<!-- Dynamically render the model properties safely -->
<h1>Hello, {{ $user->name }}</h1>
<p>Email: {{ $user->email }}</p>
</body>
</html>
Key Built-In Tools
-
Artisan CLI: A powerful built-in command line companion. Running tools like php artisan make:controller instantly stubs out boilerplate files.
-
Database Migrations: Acts like version control for databases, allowing teams to build or alter schemas programmatically using plain PHP files.
-
Authentication Starters: Out-of-the-box infrastructure toolkits like Laravel Breeze offer instant secure login, signups, and password reset setups.
In the Laravel framework, Artisan is the built-in command-line interface (CLI) used to bootstrap code, run migrations, and automate repetitive tasks. To generate boilerplate files like models, controllers, and database migrations, you run commands prefaced with php artisan make:.
Core "Make" Commands
Generate a standard Eloquent database model class inside app/Models/.
php artisan make:model Product
Generate an HTTP traffic handler class inside app/Http/Controllers/.
php artisan make:controller ProductController
Generate a database table structural script inside database/migrations/.
php artisan make:migration create_products_table
Generate a web template interface file named index.blade.php inside resources/views/products/.
php artisan make:view products.index
Real-World Workflow Example
Instead of running separate commands, you can chain flags together to build a complete backend structure in a single line.
Run this command in your terminal terminal from your project's root folder:
php artisan make:model Product -mcr
What this single command generates:
-
The Model: Creates app/Models/Product.php to map database data into PHP objects.
-
The Migration (-m): Creates a time-stamped schema file inside database/migrations/ to construct the physical database table.
-
The Resource Controller (-cr): Creates app/Http/Controllers/ProductController.php pre-populated with empty CRUD method blocks (index, create, store, show, edit, update, destroy).
Step-by-Step Implementation
- Step 1: Open the Migration
Navigate to your new file in database/migrations/ and define the database table fields:
<?php
public function up(): void
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->decimal('price', 8, 2);
$table->timestamps();
});
}
Run php artisan migrate in your terminal to build this table in your connected database.
- Step 2: Update the Controller
Open app/Http/Controllers/ProductController.php to load records from the model and pass them to a view interface:
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Illuminate\Http\Request;
class ProductController extends Controller
{
public function index()
{
// Fetch all products using Eloquent
$products = Product::all();
// Pass data to resources/views/products/index.blade.php
return view('products.index', compact('products'));
}
}
- Step 3: Map the Web Route
Register the generated controller in routes/web.php to make it accessible to your web browser:
<?php
use App\Http\Controllers\ProductController;
use Illuminate\Support\Facades\Route;
Route::resource('products', ProductController::class);
So easy, even an AI can do it!
Normally, (Like Symfony) doing all this by hand is just as fast for me. But it so much easier to just run a few commands and everything is started for you.
Using the artisan commands make starting a project from scratch fast and simple. It pretty much handles all the heavy lifting for you when deploying making Laravel a very popular choice. When properly used, (like Symfony) Laravel is very powerful and easy to use.
Development Frameworks
JS Frameworks
CSS Frameworks
More Frameworks
Social Media
---
title: Laravel
text: The Laravel MVC Framework
image: /assets/svg/laravel.svg
link:
target:
---