Laravel
Laravel
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;
Illuminate\Http\Request Object
(
[attributes] => Symfony\Component\HttpFoundation\ParameterBag Object
(
[parameters:protected] => Array
(
)
)
)
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";
}
}
}