I'm trying to create a simple Admin Panel using session in Laravel. I don't plan on using Laravel authentication. I'm getting an error. I realize that its happening because of the get method in web.php file, I even changed it to post but still not working. Kindly help, I'm getting the below error. -
RouteCollection.php line 251 at RouteCollection->methodNotAllowed(array('GET', 'HEAD'))in RouteCollection.php line 238
Login.blade.php -
@php
session_start();
echo isset($_SESSION['login']);
if(isset($_SESSION['login'])) {
header('LOCATION:dashboard'); die();
}
@endphp
<html>
<body>
<h3>Login</h3>
@php
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($username === 'admin' && $password === 'password')
{
$_SESSION['login'] = true; header('LOCATION:dashboard'); die();
} else {
echo "Username and Password do not match";
}
}
@endphp
<form action="" method="post">
Username:
<input type="text" id="username" name="username" required>
Password:
<input type="password" id="pwd" name="password" required>
<button type="submit" name="submit">Login</button>
</form>
</body>
</html>
Web.php -
Route::get('/admin', function () {
return view('admin.login');
});
Route::get('/dashboard', function () {
return view('admin.dash');
});
Dash.blade.php -
@php
session_start();
if(!isset($_SESSION['login'])) {
header('LOCATION:admin'); die();
}
@endphp
<!DOCTYPE html>
<html>
<body>
<h3>Dashboard</h3>
</body>
</html>