Using API Guard with Laravel 5.2
If you’ve been having problems with using chrisbjr’s ApiGuard library in your project after upgrading to Laravel 5.2, I’ve outlined the steps to take in order to have it working; particularly if you are getting the error below:
The error above appears because the beforeFilter
method was deprecated in Laravel 5.1, and removed in 5.2; Laravel now uses Middleware.
This change was merged into the master branch of the ApiGuard module, but for some reason is not available when you do composer update. The fix involves updating your composer.json
file to use dev-master
.
First, update your composer.json
file as follows:
Next, run composer update
for your project.
Finally, add the apiguard middleware to the $routeMiddleware
array in app/Http/Kernel.php
as shown below:
That’s it! You should be able to get back to creating amazing apps with Laravel! Till next time, bye!
I wouldn’t have been able to figure this out without the resources below; Asanteni sana!:
- Laravel Github Issue
- Pull Request on the ApiGuard repo
- And of course, SO