LARAVEL FOR BEGINNERS: Learn Coding Fast: LARAVEL PHP WEB Framework, Quick Start E book, Tutorial book with Hands-On Projects in Easy steps, An ultimate Beginner's guide by SEL TAM
Author:SEL, TAM [SEL, TAM]
Language: eng
Format: epub
Published: 2020-04-15T16:00:00+00:00
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull:: class ,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies:: class ,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:: class ,
\Illuminate\Session\Middleware\StartSession:: class ,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware \ShareErrorsFromSession:: class ,
\App\Http\Middleware\VerifyCsrfToken:: class ,
\Illuminate\Routing\Middleware\SubstituteBindings:: class ,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
*
@var array
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate:: class ,
'auth.basic' => \Illuminate\Auth\Middleware
\AuthenticateWithBasicAuth:: class ,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings:: class ,
'can' => \Illuminate\Auth\Middleware\Authorize:: class ,
'guest' => \App\Http\Middleware
\RedirectIfAuthenticated:: class ,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests:: class ,
'age' => \App\Http\Middleware\CheckAge:: class ];
}
In the above code, we have added the code, i.e., ''age' => \App\Http\Middleware\CheckAge::class' , where age is the name of the middleware. Now, we can use the 'age' middleware for some specific routes.
Step 2: Open the CheckAge.php file, which you have created as a middleware.
Step 3: Add the middleware code in the web.php file.
Route::Get('/', function ()
{
return view('welcome');
})-> middleware('age');
Route::Get('user/profile', function ()
{
return "user profile";
});
In the above code, we have added middleware in '/' root URL, and we have not added the middleware in the 'user/profile' URL.
When the parameter is passed in a URL.
web.php
Route::Get('/{age}', function ($age)
{
return view('welcome');
})-> middleware('age');
CheckAge.php
<?php
namespace App\Http\Middleware;
use Closure;
class CheckAge
{
/**
* Handle an incoming request.
*
* @param
\Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//return "middleware";
echo "this is checkage middleware";
return $next($request);
}}
Check condition in middleware
Middleware can also be used to check the condition. Let's understand through an example.
Route::Get('/{age}', function ($age)
{
return view('welcome');
})-> middleware('age');
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12568)
Hello! Python by Anthony Briggs(9912)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9795)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Dependency Injection in .NET by Mark Seemann(9336)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8295)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7761)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7049)
Microservices with Go by Alexander Shuiskov(6815)
Practical Design Patterns for Java Developers by Miroslav Wengner(6727)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6671)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6409)
Angular Projects - Third Edition by Aristeidis Bampakos(6076)
The Art of Crafting User Stories by The Art of Crafting User Stories(5603)
NetSuite for Consultants - Second Edition by Peter Ries(5543)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5344)
Kotlin in Action by Dmitry Jemerov(5062)
