Ad

Limit Access To Route By Parameter Value

- 1 answer

I have a route like the following :

Route::group([
    'prefix'    => 'reports'
], function () {
     Route::get('/points/{product_name}', ['uses' => '[email protected]'])->where('product_name', ['product1', 'product2','product3'])
});

So I would like to limit the access to this endpoint id the product name is product1, product2, product3. But with the where clause, I can only see checking with regular expression or a single value.

When I use an array like ['product1', 'product2', 'product3'], but it is throwing an error "message": "Routing requirement for "product_name" must be a string."

How can I solve this?

Ad

Answer

For routes in laravel u can use it like this:

where('product_name', 'product1|product2|product3'])

or whith array:

where('product_name', implode("|", ['product1', 'product2','product3']))

Ad
source: stackoverflow.com
Ad