SlideShare a Scribd company logo
www.binary-studio.com
Laravel Routing
Base Routing
Route::get('/users', function () {
//
});
Route::post('/user', function () {
//
});
Route::put('/user', function () {
//
});
Route::delete('/user', function () {
//
});
Route::match(['get', 'post'], '/user', function () {
//
});
Route::any('/user', function () {
//
});
Route Parameters
Required Parameters
Route::get('/hello/{username}', function ($username) {
return 'Hello, ' . $username . '!';
});
Optional Parameters
Route::get('/hello/{username?}', function ($username = null) {
if (null === $username) {
return 'Hello, everybody!';
} else {
return 'Hello, ' . $username . '!';
}
});
______________________________________________________________________
Note: Route parameters cannot contain the '-' character. Use an underscore (_) instead.
Route Filters
Route::get('/hi/{username}', function ($username) {
return 'Hello, ' . $username . '!';
})
->where('username', '[A-Za-z]+');
Route::get('/hi/{id}', function ($id) {
return 'Hello, user with ID ' . $id . '!';
})
->where('id', '[0-9]+');
Route::get('user/{name}/{age}', function ($name, $age) {
//
})
->where(['name' => '[a-z]+', 'age' => '[0-9]+',]);
Named Routes
Route::get('user/{id}/profile/name/edit', function ($id) {
//
});
url('user/1/profile/name/edit');
Route::get('user/{id}/profile/name/edit', ['as' => 'editname', function ($id) {
//
}]);
route('editname', array(1))
Actions, Middlewares
Actions:
Route::get('/user', ['uses' => 'UserController@show']);
Middlewares:
Route::get('/user', ['middleware' => 'auth', function () {
// Uses Auth Middleware
}]);
Route::get('/profile', ['middleware' => 'auth', 'uses' => 'UserController@getProfile']);
Route Groups
Prefix
Route::group(['prefix' => 'user/{id}'], 'where' => ['id' => '[0-9]+'], function()
{
Route::get('profile', function($id)
{
// URL: "/user/1/profile"
});
});
Domain
Route::group(['domain' => '{section}.google.com'], function()
{
Route::get('list/', function($section)
{
// docs.google.com/list
});
});
Namespaces
Route::group(['namespace' => 'Admin'], function()
{
Route::group(['namespace' => 'User'], function()
{
// Controllers in namespace "AppHttpControllersAdminUser"
});
});
Middlewares:
Route::group(['middleware' => 'auth'], functtion() {}]);
Route Model Binding
Route::get('/api/user/{user}', function($user) {
return AppUser::findOrFail($user);
});
Route::get('/user/{user}', function(AppUser $user) {
return $user; // json of object(AppUser)
});
Route::model('user', 'AppUser');
Route::bind('user', function($value)
{
return AppUser::find($value);
//return AppUser::where('username', $value)->first();
});
API rate limiting
Route::get('/api/search/{term}', function($term) {
return [
'results' => $term
];
});
Route::get('/api/search/{term}', function($term) {
return [
'results' => $term
];
})->middleware('throttle:60'); // 60 requests per minute
RouteServiceProvider
public function boot(Router $router)
{
parent::boot($router);
$router->model('user', 'AppUser');
}
...
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/routes.php');
});
$router->get('profile/{contactid}', function($contactId) {
return $contactId;
});
}
Request Lifecycle

More Related Content

PDF
Angular JS Routing
PDF
Angular meetup - routing and multilingual urls
PDF
Angular Promises and Advanced Routing
PDF
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
KEY
Expressを使ってみた
PDF
There's a Filter For That
PDF
Desymfony 2011 - Habemus Bundles
PPTX
Magento Live Australia 2016: Request Flow
Angular JS Routing
Angular meetup - routing and multilingual urls
Angular Promises and Advanced Routing
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
Expressを使ってみた
There's a Filter For That
Desymfony 2011 - Habemus Bundles
Magento Live Australia 2016: Request Flow

What's hot (20)

TXT
Codigo taller-plugins
ZIP
Web+GISという視点から見たGISの方向性
PPT
Nashvile Symfony Routes Presentation
PDF
Codeigniter : Custom Routing - Manipulate Uri
PDF
Code igniter parameter passing techniques
PPTX
Building a dashboard using AngularJS
PDF
router-simple.cr
PDF
Binary Studio Academy 2016: Laravel Controllers
KEY
Evrone.ru / BEM for RoR
PDF
hachioji.pm #40 : asynchronous in JS
PDF
Practica csv
KEY
Rails Routing and URL design
PDF
Laravel Routing and Query Building
PDF
Advanced RESTful Rails
PDF
DrupalCon jQuery
PDF
20150829 firefox-os
PDF
Mashing up JavaScript – Advanced Techniques for modern Web Apps
PPTX
Goodbye hook_menu() - Routing and Menus in Drupal 8
PDF
浜松Rails3道場 其の四 View編
PDF
Using and reusing CakePHP plugins
Codigo taller-plugins
Web+GISという視点から見たGISの方向性
Nashvile Symfony Routes Presentation
Codeigniter : Custom Routing - Manipulate Uri
Code igniter parameter passing techniques
Building a dashboard using AngularJS
router-simple.cr
Binary Studio Academy 2016: Laravel Controllers
Evrone.ru / BEM for RoR
hachioji.pm #40 : asynchronous in JS
Practica csv
Rails Routing and URL design
Laravel Routing and Query Building
Advanced RESTful Rails
DrupalCon jQuery
20150829 firefox-os
Mashing up JavaScript – Advanced Techniques for modern Web Apps
Goodbye hook_menu() - Routing and Menus in Drupal 8
浜松Rails3道場 其の四 View編
Using and reusing CakePHP plugins
Ad

Viewers also liked (14)

PPS
Rizz yacht d'albert_de_monaco_111
PPTX
Blogs copia
PDF
13A Final Portfolio
DOCX
Diagnóstico personal
PDF
Bee Therapy Beat Board
PDF
Shark 01
PDF
Spe 80945-ms
PPTX
Antikoagulanti, antiagreganti un trombolītiķi. Hemostāzi kavējošā terapija OR...
PDF
Gas CCUS in Mexico - Abigail Gonzalez Diaz at the UKCCSRC Gas CCS Meeting, Un...
PDF
Packer failure
PDF
Tight Reservoir Technology IUGF 20 1 2012
PDF
React – ¿Qué es React.js?
PDF
Packer milling
PPTX
Fundamentals of Petroleum Engineering Module 6
Rizz yacht d'albert_de_monaco_111
Blogs copia
13A Final Portfolio
Diagnóstico personal
Bee Therapy Beat Board
Shark 01
Spe 80945-ms
Antikoagulanti, antiagreganti un trombolītiķi. Hemostāzi kavējošā terapija OR...
Gas CCUS in Mexico - Abigail Gonzalez Diaz at the UKCCSRC Gas CCS Meeting, Un...
Packer failure
Tight Reservoir Technology IUGF 20 1 2012
React – ¿Qué es React.js?
Packer milling
Fundamentals of Petroleum Engineering Module 6
Ad

Similar to Binary Studio Academy 2016: Laravel Routing (20)

PDF
Durian: a PHP 5.5 microframework with generator-style middleware
DOCX
Laravel
ODP
Aura Project for PHP
PDF
Be RESTful (Symfony Camp 2008)
PDF
JSGeneve - Backbone.js
PDF
Micropage in microtime using microframework
PPTX
Express JS
PDF
Silex Cheat Sheet
PDF
Silex Cheat Sheet
PDF
JSDay Italy - Backbone.js
PPTX
Laravel5 Introduction and essentials
PPTX
Angular Workshop_Sarajevo2
PDF
Perl Dancer for Python programmers
PDF
Building Lithium Apps
PDF
ui-router and $state
PDF
TDC 2014 - JavaScript de qualidade: hoje, amanhã e sempre!
KEY
Intro To Sammy
PPTX
22.sessions in laravel
PDF
Building Evented Single Page Applications
PDF
Building evented single page applications
Durian: a PHP 5.5 microframework with generator-style middleware
Laravel
Aura Project for PHP
Be RESTful (Symfony Camp 2008)
JSGeneve - Backbone.js
Micropage in microtime using microframework
Express JS
Silex Cheat Sheet
Silex Cheat Sheet
JSDay Italy - Backbone.js
Laravel5 Introduction and essentials
Angular Workshop_Sarajevo2
Perl Dancer for Python programmers
Building Lithium Apps
ui-router and $state
TDC 2014 - JavaScript de qualidade: hoje, amanhã e sempre!
Intro To Sammy
22.sessions in laravel
Building Evented Single Page Applications
Building evented single page applications

More from Binary Studio (20)

PPTX
Academy PRO: D3, part 3
PPTX
Academy PRO: D3, part 1
PPTX
Academy PRO: Cryptography 3
PPTX
Academy PRO: Cryptography 1
PPTX
Academy PRO: Advanced React Ecosystem. MobX
PPTX
Academy PRO: Docker. Part 4
PPTX
Academy PRO: Docker. Part 2
PPTX
Academy PRO: Docker. Part 1
PPTX
Binary Studio Academy 2017: JS team project - Orderly
PPTX
Binary Studio Academy 2017: .NET team project - Unicorn
PPTX
Academy PRO: React native - miscellaneous
PPTX
Academy PRO: React native - publish
PPTX
Academy PRO: React native - navigation
PPTX
Academy PRO: React native - building first scenes
PPTX
Academy PRO: React Native - introduction
PPTX
Academy PRO: Push notifications. Denis Beketsky
PPTX
Academy PRO: Docker. Lecture 4
PPTX
Academy PRO: Docker. Lecture 3
PPTX
Academy PRO: Docker. Lecture 2
PPTX
Academy PRO: Docker. Lecture 1
Academy PRO: D3, part 3
Academy PRO: D3, part 1
Academy PRO: Cryptography 3
Academy PRO: Cryptography 1
Academy PRO: Advanced React Ecosystem. MobX
Academy PRO: Docker. Part 4
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 1
Binary Studio Academy 2017: JS team project - Orderly
Binary Studio Academy 2017: .NET team project - Unicorn
Academy PRO: React native - miscellaneous
Academy PRO: React native - publish
Academy PRO: React native - navigation
Academy PRO: React native - building first scenes
Academy PRO: React Native - introduction
Academy PRO: Push notifications. Denis Beketsky
Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 1

Recently uploaded (20)

PPTX
L1 - Introduction to python Backend.pptx
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ai tools demonstartion for schools and inter college
PDF
System and Network Administration Chapter 2
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
top salesforce developer skills in 2025.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
System and Network Administraation Chapter 3
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
L1 - Introduction to python Backend.pptx
VVF-Customer-Presentation2025-Ver1.9.pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ai tools demonstartion for schools and inter college
System and Network Administration Chapter 2
PTS Company Brochure 2025 (1).pdf.......
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
top salesforce developer skills in 2025.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Computer Software and OS of computer science of grade 11.pptx
Operating system designcfffgfgggggggvggggggggg
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
System and Network Administraation Chapter 3
Adobe Illustrator 28.6 Crack My Vision of Vector Design

Binary Studio Academy 2016: Laravel Routing

  • 2. Base Routing Route::get('/users', function () { // }); Route::post('/user', function () { // }); Route::put('/user', function () { // }); Route::delete('/user', function () { // }); Route::match(['get', 'post'], '/user', function () { // }); Route::any('/user', function () { // });
  • 3. Route Parameters Required Parameters Route::get('/hello/{username}', function ($username) { return 'Hello, ' . $username . '!'; }); Optional Parameters Route::get('/hello/{username?}', function ($username = null) { if (null === $username) { return 'Hello, everybody!'; } else { return 'Hello, ' . $username . '!'; } }); ______________________________________________________________________ Note: Route parameters cannot contain the '-' character. Use an underscore (_) instead.
  • 4. Route Filters Route::get('/hi/{username}', function ($username) { return 'Hello, ' . $username . '!'; }) ->where('username', '[A-Za-z]+'); Route::get('/hi/{id}', function ($id) { return 'Hello, user with ID ' . $id . '!'; }) ->where('id', '[0-9]+'); Route::get('user/{name}/{age}', function ($name, $age) { // }) ->where(['name' => '[a-z]+', 'age' => '[0-9]+',]);
  • 5. Named Routes Route::get('user/{id}/profile/name/edit', function ($id) { // }); url('user/1/profile/name/edit'); Route::get('user/{id}/profile/name/edit', ['as' => 'editname', function ($id) { // }]); route('editname', array(1))
  • 6. Actions, Middlewares Actions: Route::get('/user', ['uses' => 'UserController@show']); Middlewares: Route::get('/user', ['middleware' => 'auth', function () { // Uses Auth Middleware }]); Route::get('/profile', ['middleware' => 'auth', 'uses' => 'UserController@getProfile']);
  • 7. Route Groups Prefix Route::group(['prefix' => 'user/{id}'], 'where' => ['id' => '[0-9]+'], function() { Route::get('profile', function($id) { // URL: "/user/1/profile" }); }); Domain Route::group(['domain' => '{section}.google.com'], function() { Route::get('list/', function($section) { // docs.google.com/list }); }); Namespaces Route::group(['namespace' => 'Admin'], function() { Route::group(['namespace' => 'User'], function() { // Controllers in namespace "AppHttpControllersAdminUser" }); }); Middlewares: Route::group(['middleware' => 'auth'], functtion() {}]);
  • 8. Route Model Binding Route::get('/api/user/{user}', function($user) { return AppUser::findOrFail($user); }); Route::get('/user/{user}', function(AppUser $user) { return $user; // json of object(AppUser) }); Route::model('user', 'AppUser'); Route::bind('user', function($value) { return AppUser::find($value); //return AppUser::where('username', $value)->first(); });
  • 9. API rate limiting Route::get('/api/search/{term}', function($term) { return [ 'results' => $term ]; }); Route::get('/api/search/{term}', function($term) { return [ 'results' => $term ]; })->middleware('throttle:60'); // 60 requests per minute
  • 10. RouteServiceProvider public function boot(Router $router) { parent::boot($router); $router->model('user', 'AppUser'); } ... public function map(Router $router) { $router->group(['namespace' => $this->namespace], function ($router) { require app_path('Http/routes.php'); }); $router->get('profile/{contactid}', function($contactId) { return $contactId; }); }