php
Route::get(‘/dashboard’, ‘DashboardController@index’)->middleware(‘auth’);
php
Route::get(‘/api/data’, ‘DataController@index’)->middleware(‘throttle:10,1’);
php
Route::get(‘/api/data’, ‘DataController@index’)->middleware(‘throttle:5,1’);
php
public function handle($request, Closure $next, $role)
{
if (!auth()->check() || auth()->user()->role !== $role) {
return redirect(‘/unauthorized’);
}
return $next($request);
}
php
protected $routeMiddleware = [
// Other middleware
‘role’ => \App\Http\Middleware\RoleMiddleware::class,
];
php
Route::get(‘/admin’, ‘AdminController@index’)->middleware(‘role:admin’);
php artisan make:middleware RequestLogger
php
public function handle($request, Closure $next)
{
\Log::info(‘Request Logged:’, [
‘url’ => $request->fullUrl(),
‘method’ => $request->method(),
‘ip’ => $request->ip(),
‘time’ => now(),
]);
return $next($request);
}
php
protected $routeMiddleware = [
// Other middleware
‘log’ => \App\Http\Middleware\RequestLogger::class,
];
php
Route::get(‘/user/profile’, ‘UserProfileController@index’)->middleware(‘log’);
php
public function handle($request, Closure $next)
{
$request->validate([
‘name’ => ‘required|string|max:255’,
’email’ => ‘required|email’,
]);
return $next($request);
}
php
protected $routeMiddleware = [
// Other middleware
‘validate’ => \App\Http\Middleware\ValidateInput::class,
];
php
Route::post(‘/user/store’, ‘UserController@store’)->middleware(‘validate’);
];
If you’re looking to enhance your Laravel application, N Technolabs can help! Whether you need Laravel maintenance & support service or want to hire a Laravel consultant, our team is here to assist you. We specialize in providing tailored solutions that fit your needs. Reach out to us today to get started!
“These guys really know what they're doing. I've used them for some of my own clients and have always been happy with the results.”
“I have worked with N Technolabs on several projects, I have always received excellent work and communication from N Technolabs, I will continue to hire him for my next projects. I recommend it 100%”
We empower business success through tech and design. Where code meets creativity for digital excellence.
© ntechnolabs 2024. All rights reserved.