This is a heads up post about a pushMiddlewareToGroup bug in #laravel package development and how to fix it.
While working on one of my packages save last index or show route and redirect back after store/update/delete I encountered pushMiddlewareToGroup bug: middleware wasn't added to the web
group.
<?php
namespace Jcergolj\AfterActionRedirectUrlForLaravel;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
class AfterActionRedirectUrlForLaravelServiceProvider extends ServiceProvider
{
public function boot(Router $router)
{
$router->pushMiddlewareToGroup(
'web',
\App\Http\Middleware\SetIntendedUrlMiddleware::class
);
}
}
<?php
namespace Jcergolj\AfterActionRedirectUrlForLaravel;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Support\ServiceProvider;
class AfterActionRedirectUrlForLaravelServiceProvider extends ServiceProvider
{
public function boot(Kernel $kernel)
{
$kernel->appendMiddlewareToGroup(
'web',
\App\Http\Middleware\SetIntendedUrlMiddleware::class
);
}
}
Notice the line appendMiddlewareToGroup('web', \App\Http\Middleware\SetIntendedUrlMiddleware::class);. This small change made all the difference. I'm not exactly sure why the original version didn't work, but this solution does the trick!