Laravel Route::get using where conditions
Ad
I'm working on Laravel 5.1 and I have the following code:
//Routes.php
Route::get('/listagem/{campo}','[email protected]');
//ControllerParque.php
public function listar($campo) {
$listagem = DB::SELECT("SELECT COUNT(x.".$campo.") AS nreg, x.* FROM (SELECT * FROM computadores ORDER BY id DESC) AS x GROUP BY ".$campo." ORDER BY ".$campo." ASC");
$dados = array('listagem' => $listagem, 'campo' => $campo);
return view("ViewListagem")->with($dados);
}
I would like to restrict anything different of 'listagem/usuario' or 'listagem/tag'. I mean, if an user types in your navigator (URL bar) 'listagem/crap', it will be denied, because it's not 'listagem/usuario' or 'listagem/tag'.
I've tried 'where' clause':
Routes.php
Route::get('/listagem/{campo}','[email protected]')
->where('campo', 'usuario');
But this way I'm restricting just the one condition, this case 'listagem/usuario'.
Any idea?
Ad
Answer
Ad
You can use a regular expression in the "where" clause. usario|tag
would match only usario
or tag
http://laravel.com/docs/5.0/routing#route-parameters
Route::get('/listagem/{campo}','[email protected]')
->where('campo', 'usuario|tag');
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad