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

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



Copyright Disclaimer:
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.