Dispatch the request to the application.
public static dispatch ( Illuminate\Http\Request $request ) : Illuminate\Http\Response | ||
$request | Illuminate\Http\Request | |
return | Illuminate\Http\Response |
use Route; // Define a route for GET /home Route::get('/home', function() { echo "Welcome to the Home Page"; }); // Define a route for POST /contact Route::post('/contact', function() { echo "Contact form submitted successfully"; });
use Route; // Define a route with parameter Route::get('/user/{id}', function($id) { echo "User ID: " . $id; }); // Define a route with optional parameter Route::get('/blog/{id?}', function($id = null) { if($id) { echo "Blog ID: " . $id; } else { echo "Welcome to the Blog Page"; } });In this example, we define routes that take parameters. In the first route, we specify the `id` parameter in the URL and pass it as an argument to the callback function. In the second route, we define `id` as an optional parameter by placing a `?` after it in the URL. If the parameter is present, we display the blog ID, else we display a welcome message. Overall, the PHP Route dispatch package library allows developers to easily define and dispatch routes in their PHP applications.
public static dispatch ( Illuminate\Http\Request $request ) : Illuminate\Http\Response | ||
$request | Illuminate\Http\Request | |
return | Illuminate\Http\Response |