MethodNotAllowedHttpException in RouteCollection.php line 251: - php

AT login.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
<meta name="author" content="GeeksLabs">
<meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
<link rel="shortcut icon" href="img/favicon.png">
<title>welcome</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.css" rel="stylesheet">
<link href="css/elegant-icons-style.css" rel="stylesheet" />
<link href="css/font-awesome.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet">
<link href="css/style-responsive.css" rel="stylesheet" />
</head>
<body class="login-img3-body">
<div class="container">
<form class="login-form" method="post" action="{{ url('/dashboard') }}"> //{{ route('login') }}
<input type="hidden" name="_token" value="{{ csrf_field() }} ">
<div class="login-wrap">
<p class="login-img"><i class="icon_lock_alt"></i></p>
<div class="input-group">
<span class="input-group-addon"><i class="icon_profile"></i></span>
<input type="text" name="Username" class="form-control" placeholder="Username" autofocus>
</div>
<div class="input-group">
<span class="input-group-addon"><i class="icon_key_alt"></i></span>
<input type="password" name="password" class="form-control" placeholder="Password">
</div>
<label class="checkbox">
<input type="checkbox" value="remember-me"> Remember me
<span class="pull-right"> Forgot Password?</span>
</label>
<button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
<button class="btn btn-info btn-lg btn-block" type="submit">Signup</button>
</div>
</form>
<div class="text-right">
<div class="credits">
Developer::xxx
</div>
</div>
</div>
</body>
</html>
And web.php
Route::get('/' , ['as' => '/' , 'uses'=> 'loginController#getlogin']);
Route::post('/login', ['as' => 'login', 'uses'=> 'loginController#postlogin']);
Route::group(['middleware' =>['authen']], function ()
{
Route::get('/dashboard',['as'=>'dashboard', 'uses'=> 'dashboardController#dashboard']);
Route::get('/logout' ,['as'=>'logout', 'uses'=> 'loginController#getLogout']);
});
i am newer on laravel . i have this error happen . how to solve and
method="post" action="{{ url('/dashboard') }}"> //{{ route('login') }}
"{{ csrf_field() }} .In here on action field which url should pass .. i mean destination or same path .. i want to redirect to dashboard .. thank you :)

Try to change route
First you need to set login route url in form (action="{{ url('/login') }}") and after submit form in postlogin function use auth and check email password is correct or not.if correct than redirect url is dashboard.

check what ur route is expecting by using
php artisan route:list command in terminal
next change your form method to that
if you want user to redirect to dashboard u need to do it in ur controller`
`class ProfileController extends Controller
{
//your code here
public dashbord(){
// your code
return view("your dashboard view path");
}

Related

Laravel Select2 returns normal select

I am trying to use select2 for my laravel Create function. but it does nothing, and i followed multiple tutorials with the same results.
index.blade(my scripts are in the header)
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<title>Subfolders</title>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" integrity="sha512-nMNlpuaDPrqlEls3IX/Q56H36qvBASwb3ipuo3MxeWbsQB1881ox0cRv7UPTgBlriqoynt35KjEwgGUeUXIPnw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js" integrity="sha512-2ImtlRlf2VVmiGZsjm9bEyhjGW4dU7B6TNwh/hx/iSByxNENtj3WVE6o/9Lj4TJeVXPi4bnOIMXFIJJAeufa0A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
#stack('page_scripts')
</head>
#include('admin.file.create')
here i include the 'create.blade' file
create.blade:
<div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Add File</h1>
<div>
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div><br />
#endif
<form method="post" action="{{ route('admin.file.store') }}" enctype="multipart/form-data">
#csrf
<div class="form-group">
<label for="title">{{('title')}}*</label>
<input type="text" class="form-control" name="title" />
</div>
<div class="form-group">
<label for="value">{{('Short description')}}</label>
<input type="text" class="form-control" name="description_short" />
</div>
<div class="form-group">
<label for="name">{{('Tags')}}*</label>
<select id="tag_ids" name="tag_id[]" class="form-control" multiple>
<option value="">{{('Select Tags')}}</option>
#foreach($tags as $tag)
<option value=" {{$tag->id}}">{{$tag->name}}</option>
#endforeach
</select>
</div>
<p>* required</p>
<button type="submit" class="btn btn-primary">Add File</button>
</form>
</div>
</div>
</div>
#push('page_scripts')
<script>
$(document).ready(function() {
$('#tag_ids').select2();
});
</script>
#endpush
image of the select:
if i need to upload any more information i will gladly do so!
You need to add jQuery CDN and call the select2 function. I have attached a sample code below.
<!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>Select2</title>
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/select2#4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
</head>
<body>
<select class="js-example-basic-single" name="state">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
</select>
<!-- JS -->
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2#4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function () {
$('.js-example-basic-single').select2();
});
</script>
</body>
</html>

I'm pretty new to laravel and I'm doing user sign up and login but I'm getting an error

The POST method is not supported for this route. Supported methods: GET, HEAD.
I'm pretty new to laravel and I'm doing user sign up and login but I'm getting an error
This is the controller which is giving an error
namespace App\Http\Controllers;
use Illuminate\Http\facade;
use Request;
use DB;
class hotsmoke extends Controller
{
function login() {
return view('hot_smoke_login');
}
function signup() {
return view('sign-Up');
}
function login2() {
return view('dashboard');
}
function store() {
$uname= Request::input('name');
$uemail = Request::input('email');
$unumber= Request::input('number');
$uaddress= Request::input('address');
$upass= Request::input('password');
DB::unprepared("insert into customers (name, email,number,address,password) values ('$uname','$uemail','$unumber','$uaddress','$upass')");
return redirect('/hot_smoke_login');
}
function match2() {
$uemail = Request::input('email');
$upass = Request::input('password');
$loginData = DB::select('select password from users where email = ?', [$uemail]);
if (count($loginData) > 0){
foreach ($loginData as $tablepass) {
if (($tablepass->password) == $upass){
return view('dashboard');
}
else{
$error='Password does not match';
return view('hot_smoke_login')->with('error',$error);
}
}
}
}
}
my blade view which is not running as mentioned
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/login.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<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>Hotsmoke</title>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 p-0" style=" height: 100vh; overflow: hidden;">
<img src="images/hero-img.jpg" alt="" width="100%">
</div>
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 p-5">
<i class="fa-solid fa-arrow-left backBtn"></i>
<div class="align-items-center justify-content-center d-flex flex-column">
<h3 class="text-white">Login to <strong style="color: #ce913a;">HotSmoke</strong></h3>
<p class="mb-4 secondary-color">We know the cuisines and your taste better than anyone!</p>
<form method="post" id="login">
<div class="form-group first d-flex flex-column">
<label class="primary-color" for="username">Email</label>
<input type="text" class="email" id="username">
</div>
<div class="form-group last mb-3 d-flex flex-column">
<label class="primary-color" for="password">Password</label>
<input type="password" class="email" id="password">
</div>
<div class="d-flex mb-1 align-items-center">
<label class="control control--checkbox mb-0"><span class="caption">Remember me</span>
<input type="checkbox" checked="checked" />
<div class="control__indicator"></div>
</label>
<span class="ml-auto"><a href="forget-password.html" class="forgot-pass" style="color: #e0ae66">Forgot
Password</a></span>
</div>
Do not have an Account?
<small class="text-danger " id="error" style="display: none;"></small>
<br><br>
<button class="email-button">Log In</button>
</form>
</div>
</div>
</div>
</div>
<script src="js/bootstrap.min.js"></script>
<script src="https://kit.fontawesome.com/5e8b9def84.js" crossorigin="anonymous"></script>
<script src="js/login.js"></script>
</body>
</html>
and my routes are
Route::get('sign-Up', [hotsmoke::class, 'signup']);
Route::post('sign-Up', [hotsmoke::class, 'store']);
Route::get('hot_smoke_login', [hotsmoke::class, 'login']);
Route::get('hot_smoke_login', [hotsmoke::class, 'match2']);
please guide me
I hope this will work. In each an every input field add the name attribute and mention the name you want to call it.
For example <input type="text" class="email" name="username"> , do this to every input and after the form tag use #csrf token like this and the route name should be the action,
<form action="/sign-Up" method="post" id="login">
#csrf
...
</form>
I think the first thing you need to do is add an 'action' attribute to your form element which points to the endpoint you want to submit the form to
so in this case it will look like
action="{{ url('/sign-Up') }}"

Why my Xampp Apache server cant open one PHP script?

I have been writing one HTML page i will let below this, and a PHP script i will post too. But when i use the HTML page to write information and submit it, i get the "The requested URL was not found on this server." message, i have all files into one folder on htdocs named "html", the html page is named "index" and the script is named "test", thank you so much for your time.
[HTML code]
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/docs/4.0/assets/img/favicons/favicon.ico">
<title>Signin Template for Bootstrap</title>
<link rel="canonical" href="https://getbootstrap.com/docs/4.0/examples/sign-in/">
<!-- Bootstrap core CSS -->
<link href="../../dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="signin.css" rel="stylesheet">
</head>
<body class="text-center">
<form method="post" action="next.php">
<img class="mb-4" src="https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72">
<h1 class="h3 mb-3" font-weight="normal"> Please sign in </h1>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
<p class="mt-5 mb-3 text-muted">© 2017-2018</p>
</form>
</body>
</html>
PHP script
<?php
$handle = fopen("pruebapracticaHE.txt", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit
?>
You said that script name is test.php
but what i can see in your HTML code that you set action="next.php" in the form instead of action="test.php" the right code is :
<form method="post" action="test.php">

Symfony 4 Login forms security FileLoaderLoadException

I'm actually in a new Symfony 4 project and I got an Error
FileLoaderLoadException
There is no extension able to load the configuration for "security" (in
/home/connexio/dev/project/config/packages/security.yaml). Looked for
namespace "security", found "framework", "doctrine_cache", "doctrine",
"doctrine_migrations", "twig" in
/home/connexio/dev/project/config/packages/security.yaml (which is
loaded in resource
"/home/connexio/dev/project/config/packages/security.yaml").
I guess that I didn't understand the magic tricks of this tutorial. (The undefined routes leaves me puzzled)
https://symfony.com/doc/current/security/form_login_setup.html
I precise that I didn't configure my config/routes.yaml cause they didn't ask to and I didn't install FOSUserBundle cause it's not a symfony 4 bundle.
Instead of that my files are quite the same.
Anyone have an advice to fix it ?
Thanks for reading !
config/packages/security.yaml
security:
firewalls:
main:
anonymous: ~
form_login:
login_path: login
check_path: login
src/Controller/SecurityController.php
<?php // src/Controller/SecurityController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends Controller
{
/**
* #Route("/login", name="login")
*/
public function login(Request $request, AuthenticationUtils $authUtils)
{
// get the login error if there is one
$error = $authUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authUtils->getLastUsername();
return $this->render('security/login.html.twig', array(
'last_username' => $lastUsername,
'error' => $error));
}
}
templates/security/login.html.twig
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">
<title>Signin Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="{{ asset('/css/bootstrap.min.css') }}" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="signin.css" rel="stylesheet">
</head>
<body>
<div class="container">
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
{% if error %}
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
<form action="{{ path('login') }}" method="post" class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="username" class="sr-only">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" class="form-control" required autofocus/>
<label for="password" class="sr-only">Password:</label>
<input type="password" id="password" name="_password" class="form-control" placeholder="Password" required/>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
{#
If you want to control the URL the user
is redirected to on success (more details below)
<input type="hidden" name="_target_path" value="/account" />
#}
<button type="submit">login</button>
</form>
</div> <!-- /container -->
</body>
</html>
You are missing security component. Running composer req security should fix your problem.
For further reference check Symfony 4 documentation - Security

MethodNotAllowedHttpException in RouteCollection.php line 251

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
<meta name="author" content="GeeksLabs">
<meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
<link rel="shortcut icon" href="img/favicon.png">
<title>welcome</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.css" rel="stylesheet">
<link href="css/elegant-icons-style.css" rel="stylesheet" />
<link href="css/font-awesome.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet">
<link href="css/style-responsive.css" rel="stylesheet" />
</head>
<body class="login-img3-body">
<div class="container">
<form class="login-form" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="login-wrap">
<p class="login-img"><i class="icon_lock_alt"></i></p>
<div class="input-group">
<span class="input-group-addon"><i class="icon_profile"></i></span>
<input type="text" name="Username" class="form-control" placeholder="Username" autofocus>
</div>
<div class="input-group">
<span class="input-group-addon"><i class="icon_key_alt"></i></span>
<input type="password" name="password" class="form-control" placeholder="Password">
</div>
<label class="checkbox">
<input type="checkbox" value="remember-me"> Remember me
<span class="pull-right"> Forgot Password?</span>
</label>
<button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
<button class="btn btn-info btn-lg btn-block" type="submit">Signup</button>
</div>
</form>
<div class="text-right">
<div class="credits">
Developer::prakash
</div>
</div>
</div>
</body>
</html>
Its my blade file ,but it cant work properly how can i do it workable ?? i think it problem on action="{{ route('login') }} when i click login bottom it shows
Whoops, looks like something went wrong.
MethodNotAllowedHttpException in RouteCollection.php line 251: How can i solve this??
You are missing method='post', I hope you have declared the route correctly in routes.php
Route::post('/post-form', 'YourController#saveDataFunction'); declare the route properly, if the method is GET write it as Route::GET else this would work fine.
MethodNotAllowedHttpException clearly means the route is not found, means it's missing in the collection OR you declared it differently.
If you don't specify method attribute GET is assumed. This exception means that Laravel couldnot find the specified route.
Which in your case appears to be that you have declared a post route in your routes/web.php file.
Either, edit your web.php file OR specify a method="post" attribute on your form.

Categories