Route::enableFilters(['auth']); Route::get('/dashboard', function() { return "You have access to the dashboard"; }); Route::filter('auth', function() { if (! Auth::check()) { return redirect('/login'); } });
Route::enableFilters(['validate']); Route::post('/create-user', function() { // Create new user }); Route::filter('validate', function() { $rules = [ 'name' => 'required|string', 'email' => 'required|email', 'password' => 'required|min:6', ]; $data = request()->all(); $validator = Validator::make($data, $rules); if ($validator->fails()) { return response()->json(['error' => $validator->errors()], 400); } });These examples are most likely using the Laravel framework, a popular PHP framework that comes with built-in routing capabilities and a multitude of features for building web applications.