🔰 Basic Routing in Laravel
Routing is the starting point of any Laravel application. Let's explore how to define simple routes to respond to browser requests.
📁 Route File Location
Basic routes are defined in routes/web.php. This file handles routes intended for the web (HTML views, CSRF protection, etc.).
🧱 Basic Route Syntax
Route::get('/path', function () {
return 'Hello, world!';
});
This defines a route for /path that returns a plain string.
🛠 Common Methods
Route::get()– Handles GET requests (links)Route::post()– Handles POST requests (forms)Route::put()– Handles PUT requests (updates)Route::delete()– Handles DELETE requestsRoute::any()– Accepts any HTTP method
📄 Returning Views
You can return a Blade view instead of a string:
Route::get('/', function () {
return view('welcome');
});
This will load resources/views/welcome.blade.php.
🔢 Route with Parameters
Capture values from the URL:
Route::get('/user/{id}', function ($id) {
return "User ID: " . $id;
});
Access this with: /user/5


