How many types of route?
✅ 1. Basic Route This is the simplest form of routing using a closure.
This is the simplest form of routing using a closure.
Route::get('/hello', function () {
return 'Hello, World!';
});
✅ 1. Basic Route This is the simplest form of routing using a closure.
This is the simplest form of routing using a closure.
Route::get('/hello', function () {
return 'Hello, World!';
});
View route
Route::view('/about', 'about');
//You can also pass data
Route::view('/greet', 'greeting', ['name' => 'John']);
✅ 1. Basic Route This is the simplest form of routing using a closure.
This is the simplest form of routing using a closure.
Route::get('/hello', function () {
return 'Hello, World!';
});
✅ 1. Basic Route This is the simplest form of routing using a closure.
This is the simplest form of routing using a closure.
Route::get('/hello', function () {
return 'Hello, World!';
});
View route
Route::view('/about', 'about');
//You can also pass data
Route::view('/greet', 'greeting', ['name' => 'John']);
Redirect route
Route::redirect('/home', '/dashboard');
//You can also pass specific status code
Route::redirect('/old', '/new', 301);
Controller routes
Route::get('/user/{id}', [UserController::class, 'show']);
Route with parameter
Route::get('/post/{id}', function ($id) {
return "Post ID: " . $id;
});
Named route
Group routes with shared attributes like middleware, prefix, or namespace.
Route::get('/profile', [UserController::class, 'profile'])->name('profile');
Route group
✅ 1. Basic Route This is the simplest form of routing using a closure.
This is the simplest form of routing using a closure.
Route::get('/hello', function () {
return 'Hello, World!';
});
✅ 1. Basic Route This is the simplest form of routing using a closure.
This is the simplest form of routing using a closure.
Route::get('/hello', function () {
return 'Hello, World!';
});
View route
Route::view('/about', 'about');
//You can also pass data
Route::view('/greet', 'greeting', ['name' => 'John']);
Redirect route
Route::redirect('/home', '/dashboard');
//You can also pass specific status code
Route::redirect('/old', '/new', 301);
Controller routes
Route::get('/user/{id}', [UserController::class, 'show']);
Route with parameter
Route::get('/post/{id}', function ($id) {
return "Post ID: " . $id;
});
Named route
Group routes with shared attributes like middleware, prefix, or namespace.
Route::get('/profile', [UserController::class, 'profile'])->name('profile');
Route group
Route::prefix('admin')->group(function () {
Route::get('/dashboard', function () {
return 'Admin Dashboard';
});
});
Resource route
Generates routes like:
GET /posts
POST /posts
GET /posts/{id}
PUT /posts/{id}
DELETE /posts/{id}
Route::resource('posts', PostController::class);
✅ 9. API Resource Route
Same as resource but optimized for APIs (no create and edit).
Route::apiResource('users', UserController::class);
Fallback routes
Handles 404s when no other route matches.
Route::fallback(function () {
return response()->json(['message' => 'Page Not Found.'], 404);
});
Route with Middleware
Route::get('/dashboard', function () {
return 'Dashboard';
})->middleware('auth');
Comments
Comments:
No comments yet. Be the first to comment!