Day2-Php Web Application Framework
Day2-Php Web Application Framework
APPLICATION
FRAMEWORK:
LARAVEL
Day 2
Routing
Controllers
Routing
What is Routing?
Syntax:
Simple Redirect:
Parameters:
URL: /about
View File: resources/views/about.blade.php
Data (optional): Pass variables to the view (e.g., $title).
Route Parameters
Required Parameters:
Optional Parameters:
Constraints:
Named Routes
Key Features:
• Methods: Actions like index(), store(), update().
• Request Handling: Access input data via Request $request.
• Response Return: Views, JSON, redirects, etc.
Single Action
Controller
Purpose:
• Handle a single action (e.g., contact form submission).
• Uses the __invoke() magic method.
Use Case: Simplify routes with one-off logic (no need for
multiple methods).
Controller Middleware
What is Middleware?
•Filters HTTP requests (e.g., auth, logging).
Common Middleware:
auth, throttle, verified, role:admin.
Restful Resource
Controller
Options:
Limit actions: ->only(['index', 'show'])
Exclude actions: ->except(['destroy'])
Restful Resource Controller
This generates a controller In routes/web.php:
(app/Http/Controllers/PostController.php) with all
RESTful methods:
Thank you