Academic Session 2025-26
ODD Semester Jul-Dec 2025
UNIVERSITY INSTITUTE OF COMPUTING
Bachelor of Computer Application(BC201)
Semester-VI
Advance Web Development using PHP
(23CAH-302)
Unit No.1 Chapter No. 3 Lecture No.1.3.1
Topic : __Routing
Gurpreet Kaur E12934 Assistant professor
PHP Routing - Introduction
Routing is the process of directing an HTTP request to a specific piece of
code (controller, view, or function).
Essential part of modern PHP web applications.
Frameworks like Laravel and Symfony provide robust routing systems.
In a typical MVC application, routes are the entry points.
Routing is the process of defining how your PHP application should
respond to incoming HTTP requests (like GET, POST, etc.). It connects
URLs to specific code, usually functions or controller methods.
Laravel Route Files
• [Link] – Routes for web (with sessions & CSRF protection).
• [Link] – Routes for RESTful APIs.
• [Link] – Console/Artisan command routes.
• [Link] – Broadcast channel definitions.
• These files are auto-loaded by Laravel.
• // [Link]
• $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
• switch ($uri) {
• case '/':
• require '[Link]';
• break;
• case '/about':
• require '[Link]';
• break;
• default:
• http_response_code(404);
• echo "404 Not Found";
• }
Defining Routes in Laravel
• Route::get('/home', function () { return 'Welcome Home!'; });
• Route::post('/submit', function () { return 'Form submitted!'; });
• Route::get('/user/{id}', [UserController::class, 'show']);
• Supports dynamic parameters and clean syntax.
File Purpose
[Link] For browser-based routes (uses session, CSRF)
[Link] For stateless API routes (uses api middleware)
[Link] For defining custom Artisan commands
[Link] For broadcasting (WebSockets)
Common Route Functions in
Laravel
• Route::get() – Handles HTTP GET requests.
exampleRoute::get('/user/{id}', [UserController::class, 'show']);
• Route::post() – Handles HTTP POST requests.
• Route::put() / patch() – For updating resources.
• Route::delete() – For deleting resources.
• Route::any() – Accepts all request types.
• Route::redirect() – Redirects one URL to another.
• Route::view() – Returns a view directly.
Uses of Routing in PHP
Frameworks
• Maps URL requests to logic (controllers/functions).
Route::get('/user/{id}', [UserController::class, 'show']);
• Allows clean, SEO-friendly URLs.
• Makes RESTful API development easier.
• Enables middleware (e.g., auth) for route protection.
• Simplifies testing and maintenance.
• Encourages separation of concerns (MVC).
• Syntax
• Route::get('/dashboard', function () {
• return view('dashboard');
• });
.1. URL Mapping
Connects incoming HTTP requests to appropriate logic.
Maps URLs like /user/5 to functions or controllers.
Example:
php
Route::get('/user/{id}', [UserController::class, 'show']);
2. Clean, Readable URLsPromotes SEO-friendly and human-readable [Link] ?page=contact type URLs.
3. HTTP Verb FilteringHandles different HTTP methods:GET for reading dataPOST for creating dataPUT/PATCH
for updating dataDELETE for deleting.
4. Dynamic Parameters in URLsAccepts variables within routes:phpCopy codeRoute::get('/post/{slug}',
function ($slug) { return "Post: $slug";});
22/09/2025 7
• 5. Controller BindingDirectly calls a controller method:phpCopy codeRoute::get('/profile',
[ProfileController::class, 'show']);
• 6. Middleware IntegrationRoutes can be protected using middleware like auth, admin, [Link]
codeRoute::get('/admin', function () { return 'Admin Dashboard';})->middleware('auth');
• 7. Route GroupingApply common prefixes, namespaces, or middleware to multiple [Link]
codeRoute::prefix('admin')->group(function () { Route::get('/users', 'AdminController@users');});
8. Fallback and Error HandlingDefine custom 404 or fallback routes:phpCopy codeRoute::fallback(function ()
{ return 'Page Not Found';});
22/09/2025 8
Quiz/ FAQ’s
• Which file handles web interface routes in
Laravel?
•Which file is used for API route definitions?
•What artisan command creates a FAQ’s
Quiz/ new controller?
•What is the default HTTP method used by this
route?
22/09/2025 9
Class wise Feedback
Class-Wise Feedback
22/09/2025 10
Relevant learning resources
• [Link]
• [Link]
• [Link]
relevant learning resources
22/09/2025 11
Links and Books
Text books
• Laravel Design Patterns and Best Practices - Book by Arda Kilicdagi and HIbrahim Yilmaz
• Laravel: Up and Running: A Framework for Building Modern PHP Apps - Book by Matt Stauffer
References books
• Professional WordPress: Design and Development by Brad Williams
• Step-By-Step WordPress for Beginners: How to Build a Beautiful Website on Your Own Domain from
Scratch by Mike Taylor
Links
1.[Link]
2. [Link]
3. [Link]
4. [Link]
22/09/2025 12
THANK YOU
13