Laravel is a popular PHP framework used to build modern websites and web applications. It provides tools for routing, database operations, authentication, validation, sessions, and more.
In this lesson, you will learn what Laravel is, why developers use it, how it works, and how it differs from core PHP.
Laravel is an open-source web application framework written in PHP. It provides a structured way to develop secure and maintainable web applications.
Laravel is used to build:
Laravel provides reusable components and conventions so developers do not need to write every feature from scratch.
Example:
Laravel Application
|
|-- Routes
|-- Controllers
|-- Models
|-- Views
|-- Database
|-- Middleware
|-- Authentication
These components work together to handle user requests and generate responses.
A framework provides a predefined structure, reusable tools, and conventions for building applications.
Without a framework, developers often need to organize routing, database access, validation, and application structure themselves.
Core PHP example:
<?php
$name = "Rahul";
echo "Welcome " . $name;
?>
This simple program can be written directly in PHP. However, a large application needs additional structure for handling many pages, users, and database records.
Laravel approach:
Route
|
Controller
|
Model (when database access is needed)
|
View or JSON Response
Laravel provides tools for organizing these responsibilities. A controller does not always need a model or a view; it can also return a redirect, JSON response, or another response type.
Laravel offers several useful features:
These features can reduce repetitive work and make applications easier to maintain.
| Core PHP | Laravel |
|---|---|
| Write application structure yourself. | Provides a predefined application structure. |
| Routing must be implemented or organized manually. | Provides a routing system. |
| Database access can use PDO or MySQLi. | Provides Eloquent ORM and a query builder, as well as database access options. |
| Reusable templates need to be organized manually or with other tools. | Provides the Blade template engine. |
| Validation logic must be implemented or added using libraries. | Provides a validation system. |
| Suitable for small scripts and custom applications. | Suitable for structured web applications and APIs. |
Laravel is built with PHP. Learning core PHP first makes it easier to understand how Laravel works.
A typical Laravel web request follows this general flow:
User opens a URL
|
v
Web Server
|
v
Laravel Entry Point
|
v
Middleware
|
v
Route
|
v
Controller
|
v
Model / Database (if required)
|
v
View or JSON Response
|
v
User receives the response
Example:
A user opens a student list page. Laravel matches the URL to a route, runs the required middleware, executes the controller, retrieves student records if needed, and returns a view containing the results.
This is a simplified flow. The exact steps depend on the route, middleware, and response being used.
MVC stands for Model-View-Controller. It is a software architectural pattern used to organize application responsibilities.
Example file names:
app/Models/Student.php
app/Http/Controllers/StudentController.php
resources/views/students/index.blade.php
For a student management application, the model can work with student records, the controller can retrieve them, and the view can display them.
Before starting Laravel, learn these fundamentals:
Common development tools:
Composer is PHP's dependency manager and is used to install Laravel and manage its packages.
Laravel can be used to create projects such as:
For example, a student management system can include student registration, course management, attendance, fee records, and reports.
Laravel provides the application structure and tools needed to build these features, while the developer defines the business rules and user experience.
Before creating your first Laravel project, complete these introductory tasks.
Practice question:
Suppose you want to build a coaching institute website with student registration, attendance, and fee management. Explain how Laravel could help you organize this application.
In the next lesson, you will learn about Laravel's system requirements and installation.
1. Laravel is a framework written in which language?
2. What does MVC stand for?
3. Which tool is commonly used to install Laravel dependencies?