juergen
juergen

Reputation: 111

Laravel 5.1 Pass middleware parameters as array

i have a route group in which i will check the rank of the user by middleware:

Route::group(['prefix' => 'expert'], function () {
    Route::group(['prefix' => 'partner', 'middleware' => 'rank:4,5'], function () {
        Route::get('/search', 'PartnerController@getSearch');
        Route::post('/result', 'PartnerController@postSearch');
    });
});

the middleware is registred in the kernel.php :

 protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'rank' => \App\Http\Middleware\checkRank::class,
];

here is my class :

namespace App\Http\Middleware;

use Closure;
use Auth;

class checkRank {

    public function handle($request, Closure $next, $ranks) {

        //return $next($request);
        return print_r($ranks);

    }
}

all i wanna see is the array with the values [4,5]

but all i get is 4

PHP-Version is 5.6.11

trying this way according to : http://laravel.com/docs/5.1/middleware#middleware-parameters

Upvotes: 1

Views: 2721

Answers (1)

juergen
juergen

Reputation: 111

public function handle($request, Closure $next, ...$ranks) {}

i forgot the three dots in front of $ranks

Upvotes: 10

Related Questions