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
Laravel
Using Laravel 4 App Bind to bind classes
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