• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar

Jeff Mould

A Tech Blog by Jeff Mould

  • Home
  • Resources
    • Website Resources
    • How To Use WordPress
  • Jeff Mould
    • About Jeff Mould
    • Jeff Mould Links
    • Disclosure
  • Contact Jeff Mould
You are here: Home / Archives for middleware

middleware

Pass parameters to middleware in Laravel 5

April 22, 2015 by Jeff Mould 4 Comments

I recently had the need to pass parameters to middleware for authentication purposes. I wanted to declare a custom role for each route, have that role passed to the middleware, and if the user held that role the route would pass. The solution actually turned out to be quite simple and using a solution I found for Laravel 4 I was able to make this work for Laravel 5. In particular I made this solution for use with Cartalyst Sentry, but can be easily adapted to work with any use. First things first, let's create a simple middleware. We will call this RoleChecker and save it to the Http\Middleware directory. Note that you will need to change the "YourAppNameHere" name to work with your installation. [crayon-5def6f4f937e5207099958/] Now we need Laravel to recognize our custom middleware so we open the Http/Kernel.php file and add the following line to the $routeMiddleware array: [crayon-5def6f4f937eb607129331/] Finally, we can start passing parameters to our … [Read more...] about Pass parameters to middleware in Laravel 5

Filed Under: Laravel 5 Tagged With: cartalyst, Cartalyst Sentry 2, jeff mould, Laravel, laravel 5, middleware, routes, sentry

Primary Sidebar

Connect With Me

  • Facebook
  • GitHub
  • Google+
  • Instagram
  • LinkedIn
  • Pinterest
  • Tumblr
  • Twitter
  • YouTube

Top Posts & Pages

  • Laravel 5.4 Redirect after Password Reset Email Sent
  • The mixed up pricing of SiriusXM and SiriusXM Discounts
  • Laravel 5.2 - Forcing HTTPS Routes when using SSL
  • Bootstrap 4 Mobile Menu - Collapsible Nav
  • Exclude Subdirectory from Routing in Laravel 5

Copyright © 2016 - Jeff Mould - All Rights Reserved