Laravel route middleware outputting my log

Published

I’m trying to run some middleware on my routes via my package’s service provider before the routes run in my Laravel project but I’m not seeing my var_dump despite running php artisan route:list showing that the BeforeMiddleware is applied. Am I using the wrong middleware?

My service provider:

<?php

namespace CompanyFudgeInboundManagementBridge;

use IlluminateSupportFacadesRoute;
use IlluminateSupportServiceProvider;
use CompanyFudgeInboundManagementBridgeHttpMiddlewareBeforeMiddleware;

class FudgeInboundManagementBridgeServiceProvider extends ServiceProvider
{

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerFiles();
    }

    /**
     * Register files
     */
    protected function registerFiles(): void
    {
        Route::middleware(BeforeMiddleware::class)->group(function () {
            $this->loadRoutesFrom(__DIR__.'/routes/fudge-routes.php');
        });

        $this->publishes([
            __DIR__ . '/config/FudgeInboundManagementBridge.php' => config_path('FudgeInboundManagementBridge.php'),
        ], 'config');
    }
}

My middleware:

<?php

namespace CompanyFudgeInboundManagementBridgeHttpMiddleware;

use Closure;
use IlluminateHttpRequest;

class BeforeMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        var_dump('hello from before middleware - bridge');
        die;
        // return $next($request);
    }
}

Seems like it’s not triggering?

Source: Laravel

Published
Categorised as laravel, php Tagged ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq