1

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

4
  • That's strange, here is the same code and it works. ahesanalisuthar.wordpress.com/2015/06/04/… Commented Jul 30, 2015 at 9:52
  • yes i know this artikel :-( i also get this error: UnexpectedValueException in Response.php line 403: The Response content must be a string or object implementing __toString(), "boolean" given. Commented Jul 30, 2015 at 10:01
  • have you tried it without a group just to check if that works? Commented Jul 30, 2015 at 10:21
  • yes i did but wont work Commented Jul 30, 2015 at 10:37

1 Answer 1

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

i forgot the three dots in front of $ranks

Sign up to request clarification or add additional context in comments.

1 Comment

after some research it makes sense now. It's a new feature of php 5.6. In your case it means for the handle function: first varibale is the request, then the next variable and the rest will be stored are an array in $ranks ;) lornajane.net/posts/2014/php-5-6-and-the-splat-operator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.