Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Middleware In laravel 4.x

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 698
    Comment on it

    Middleware is one of the important part of any application. The code which we want to stick between request/response life cycle which is not necessary part of our application logic. That is called as middleware.

    Let take a example to know more about middleware.

    1)   Adding session support
    2)   Parsing query strings
    3)   Implementing rate-limiting
    4)   Sniffing for bot traffic
    5)   Adding logging
    6)   Parsing request JSON
    7)  Anything else related to the request/response lifecycle
    


    Laravel's Implementation Step By Step:

    For implement middleware we use HttpKernelInterface. In laravel 4.x we have Foundation/Application (In built functionality). By adding this we are able to integrate middle ware in laravel.

    Example:

    Middleware may be specified on controller routes like so:

    Route::get('profile', [
        'middleware' => 'auth',
        'uses' => 'UserController@showProfile'
    ]);
    


    Additionally, you may specify middleware within your controller's constructor:

    class UserController extends Controller {
    
        /**
         * Instantiate a new UserController instance.
         */
        public function __construct()
        {
            $this->middleware('auth');
    
            $this->middleware('log', ['only' => ['fooAction', 'barAction']]);
    
            $this->middleware('subscribed', ['except' => ['fooAction', 'barAction']]);
        }
    
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: