• 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 Laravel

Laravel

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-5def7c770eaf9704636016/] 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-5def7c770eb00203838848/] 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

Using Laravel 4 App Bind to bind classes

February 16, 2014 by Jeff Mould Leave a Comment

When developing large applications one of the most frustrating parts can be keeping track of whether a class is loaded or not and if you have created an instance of that class. With Laravel 4 there is an easy solution to this problem by using binding classes to your app. When you use the Laravel 4 app bind combined with the autoloader you not only don't have to worry about whether the class file was loaded, but you don't have to worry about initializing the class either. You may think this is going to be some long, technical post, but this is probably one of the easiest things to do, however, the Laravel documentation is a bit limited with the exact use so I thought I would take a minute to explain. Let's say your application needs a helper class. You want that helper class to be available throughout your app without having to load the class each time you need it. For purposes of this example, let's call this class Foo and here is our little … [Read more...] about Using Laravel 4 App Bind to bind classes

Filed Under: Laravel Tagged With: App::bind, App::make, jeff mould, Laravel, Laravel 4, PHP

  • « Previous Page
  • Page 1
  • Page 2

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
  • Exclude Subdirectory from Routing in Laravel 5
  • Laravel 5.2 - Forcing HTTPS Routes when using SSL
  • Bootstrap 4 Mobile Menu - Collapsible Nav

Copyright © 2016 - Jeff Mould - All Rights Reserved