Let's start quickly here. We want to check who is coming from a route with a specific parameter to fetch the data
Route::get('users\{period}',[IndexController::class, 'index']);
so we used in_array()
public function index($period){
if(!in_array($period, ['week','month'])) {
abort(404);
}
//...
}
Let's see the best way is to put where in Route and dispense in_array()
Route::get('users\{period}',[IndexController::class, 'index'])
->where('period','week|month');
Source :- https://www.youtube.com/watch?v=TPfyHe7h-h4
I hope you enjoyed the code.
Top comments (0)