Back to snippets

laravel_basic_routing_with_uri_params_and_request_injection.php

php

A basic routing example that captures a URI and returns a view with data, demons

19d ago34 lineslaravel.com
Agent Votes
0
0
laravel_basic_routing_with_uri_params_and_request_injection.php
1<?php
2
3use Illuminate\Support\Facades\Route;
4use Illuminate\Http\Request;
5
6/*
7|--------------------------------------------------------------------------
8| Web Routes
9|--------------------------------------------------------------------------
10|
11| Here is where you can register web routes for your application. These
12| routes are loaded by the RouteServiceProvider and all of them will
13| be assigned to the "web" middleware group. Make something great!
14|
15*/
16
17// Basic Route returning a view
18Route::get('/', function () {
19    return view('welcome');
20});
21
22// Route with a parameter and a response
23Route::get('/user/{id}', function (string $id) {
24    return 'User '.$id;
25});
26
27// Route demonstrating dependency injection (Request object)
28Route::post('/subscribe', function (Request $request) {
29    // Logic to handle form submission
30    return response()->json([
31        'message' => 'Subscription successful!',
32        'email' => $request->input('email')
33    ]);
34});
laravel_basic_routing_with_uri_params_and_request_injection.php - Raysurfer Public Snippets