Explain the MVC (Model-View-Controller) pattern as implemented in Laravel.
Last updated
MVC separates an application into three responsibilities: Models handle data and business rules, Views render output, and Controllers coordinate between them. Laravel implements this with Eloquent models, Blade views, and controller classes wired together by routing.
Model: Usually an Eloquent class mapping to a table; holds data access, relationships, and domain logic.
View: Blade templates (
.blade.php) that render HTML from data passed in; no business logic.Controller:
Receives the request, calls models/services, and returns a response or view.
Kept thin: heavy logic belongs in models or service classes.
The flow:
A route in
routes/web.phpmaps a URL to a controller method.The controller queries a model and passes data to a view.
The view renders and the response goes back to the browser.
[lang:php]
// routes/web.php
Route::get('/users', [UserController::class, 'index']);
// Controller
public function index() {
$users = User::all(); // Model
return view('users.index', compact('users')); // View
}