Ken-vdE's avatar

Ken-vdE wrote a reply+100 XP

2mos ago

You can add this to your AppServiceProvider::boot():

        /** {@see Router::dispatchToRoute()}. */
        \Route::matched(function(RouteMatched $event) {
            if ($event->route->getName() === 'the.route.name') {
                $event->route->middleware('whatever-extra-middleware');
            }
        });

You could also use $event->route->named('something.with.wildcard.*') or other neat stuff (checkout vendor/laravel/framework/src/Illuminate/Routing/Route.php).

Ken-vdE's avatar

Ken-vdE wrote a reply+100 XP

2mos ago

TL;DR:
From my Stackoverflow post (stackoverflow.com/a/79894634/3017716):

\Blade::directive('someDirective', function($expression) {
    return <<<PHPSTRING
        <?php (function(\$param1, \$param2) {
            // Do something with the params, e.g.:
            \$param1 = 'prefix' . \$param1;
            echo '<div>' . \$param1 . \$param2 . '</div>';
        })($expression); ?>
        PHPSTRING;
});
Ken-vdE's avatar

Ken-vdE liked a comment+100 XP

5mos ago

In case the problem happened to someone else : After many unsuccessful tries, I recently updated my code and cleaned the cache (optimize:clear) and it seemed to work again...