0
0
Laravelframework~30 mins

Form input in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Building a Simple Laravel Form Input
📖 Scenario: You are creating a simple web page where users can submit their name using a form. This form will collect the input and prepare it for processing.
🎯 Goal: Build a Laravel form that accepts a user's name and prepares it for submission.
📋 What You'll Learn
Create a route for the form display
Create a Blade view with a form containing a text input named username
Add a CSRF token field inside the form
Add a submit button labeled Submit
💡 Why This Matters
🌍 Real World
Forms are everywhere on websites for collecting user data like names, emails, and messages. This project shows how to build a simple form in Laravel.
💼 Career
Understanding form input handling is essential for backend and full-stack developers working with Laravel to create interactive web applications.
Progress0 / 4 steps
1
Create a route for the form
In the routes/web.php file, create a GET route with the URL /userform that returns the view named userform.
Laravel
Need a hint?

Use Route::get with the URL '/userform' and return view('userform').

2
Create the Blade view with a form
Create a Blade file named userform.blade.php in the resources/views folder. Inside it, add a form with method POST and action /submitname. Add a text input with the name username.
Laravel
Need a hint?

Use a <form> tag with method="POST" and action="/submitname". Inside, add <input type="text" name="username">.

3
Add CSRF token and submit button
Inside the form in userform.blade.php, add the Blade directive @csrf for security. Then add a submit button with the text Submit.
Laravel
Need a hint?

Use @csrf inside the form and add <button type="submit">Submit</button>.

4
Create POST route to handle form submission
In routes/web.php, add a POST route for /submitname that accepts the request and returns a simple string with the submitted username using request('username').
Laravel
Need a hint?

Use Route::post('/submitname', function () { return 'Hello, ' . request('username'); });.