C
C
chelkaz2016-11-20 00:57:35
Laravel
chelkaz, 2016-11-20 00:57:35

Is it possible to exclude a parameter in the router?

How to apply to the first one so that it does not take into account the parameter in the id word remove
Is there something like this? ->name('upload.index')->where('id', ''!=, 'remove')
Tried the regex from the docks, but it doesn't help. There's an example like this - ->where('id', '[0-9]+');
I tried like this: ->where('id', '![remove]'); and so: ->where('id', '[!remove]');
Maybe I'm not doing the regular expression right?

Route::get('/upload/{id}', '[email protected]_index')->name('upload.index');
Route::get('/upload/remove', '[email protected]_remove')->name('upload.remove');

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
holfza, 2016-11-20
@holfza

May need:
put higher than:
Routes are processed from top to bottom.

E
Ernest Faizullin, 2016-11-20
@erniesto77

such an option

Route::get('/upload/{id}', '[email protected]_index')->where('id', '^(!remove$)')->name('upload.index');
Route::get('/upload/remove', '[email protected]_remove')->name('upload.remove');

U
UnQuaiz, 2016-11-20
@UnQuaiz

It is wrong to restrict a route by what it should not accept.
Correctly - to define what parameters it SHOULD accept. Because the number of values ​​that should not take - can increase, and route should not respond to them.
So:

Route::get('/upload/{id}', function(){
    return 'id integer';
})->where('id','[\d]+')
    ->name('upload.index');

Route::get('/upload/remove', function(){
    return 'remove';
})->name('upload.remove');

If it does not work, then some kind of route works earlier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question