yoyoma
yoyoma

Reputation: 3536

Lumen middleware closure error

In Lumen 5.5, I have modified the example middleware

<?php

namespace App\Http\Middleware;

use Closure;
use App\Client;

class CheckHeaders
{
    public function handle($request, Closure $next)
    {
    ...

    return $next($request);
    }
}

In bootstrap/app, I've added

$app->routeMiddleware([
'client' => App\Http\Middleware\CheckHeaders::class,
]);

And attached the middleware to the route:

$router->get('api/tokens', ['middleware' => 'client'], 'TokensController@index');

When I try instead to use the facade

Route::get('api/tokens', 'TokensController@index')->middleware('client');

This time the error is Call to undefined method Laravel\Lumen\Routing\Router::middleware()

I'm not sure if its different in Lumen as I've done this before, but now getting error

Undefined variable: closure
...
in RoutesRequests.php (line 286)

Upvotes: 1

Views: 1403

Answers (1)

Niklesh Raut
Niklesh Raut

Reputation: 34924

Try like this in two param instead three

 $app->get('api/tokens', [
      'middleware' => 'client'
      'as' => 'tokens', 
      'uses' => 'TokensController@index'
  ]);

Upvotes: 3

Related Questions