0% found this document useful (0 votes)
10 views5 pages

Laravel

The document discusses submitting forms in Laravel using a login form as an example. It shows the form markup, routes, controller method, and output of submitting the form and accessing the request data.

Uploaded by

nairananth20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Laravel

The document discusses submitting forms in Laravel using a login form as an example. It shows the form markup, routes, controller method, and output of submitting the form and accessing the request data.

Uploaded by

nairananth20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

{ Form

Submitting In
Laravel
- By Aditya Nair

... }
Demo Form:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<h1 class="py-3 text-center">Login</h1>
<form method="post" action="{{route('authentication')}}">
@csrf>
<input type="text" name="username" class="form-control text-center" id="username" placeholder="Username" style="font-weight:600;" required>
<label for="username">Username</label>
<input type="password" name="password" class="form-control text-center" id="password" placeholder="Password" style="font-weight:600;" required>
<label for="password">Password</label>
<button type="submit" name="submit" class="btn btn-danger">Admin Login</button>
<br>
</form>
</body>
</html>

Output :
Web.php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

Route::get('/',[UserController::class,'index'])->name('index');
Route::post('/authentication' , [UserController::class , 'authentication'])->name('authentication');

UserController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller


{
public function index()
{
return view('login');
}

public function authentication(Request $request)


{
echo"<pre>";
print_r($request);
}
}
Output :

Illuminate\Http\Request Object
(
[attributes] => Symfony\Component\HttpFoundation\ParameterBag Object
(
[parameters:protected] => Array
(
)
)

[request] => Symfony\Component\HttpFoundation\InputBag Object


(
[parameters:protected] => Array
(
[_token] => V62yNr81yFw53V0urMNT8BRJw7FslatpaMbPdU6g
[username] => admin
[password] => admin
[submit] =>
)
)

)
UserController.php Input
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request; Username : admin
Password : admin
class UserController extends Controller
{
public function index()
{
return view('login');
}
public function authentication(Request $request)
{
$username = $request['username'];
$password = $request['password'];
if ($username == "admin")
{
if($password == "admin")
{
echo "Welcome";
}
else Wrong Input
{
echo "Invalid";
}
}
else
{
echo "Invalid";
}
}
}

You might also like