why auth its not working in my validation and its showing anything wrong - laravel-5.6

im just new in laravel and i dont know whats wrong with my code its not redirecting
public function login(Request $request){
$this->validate($request, [
'email'=> 'required|max:32',
'password'=> 'required|confirmed|max:32|min:8',
]);
if (Auth::attempt(['email'=>$request->email,'password'=>$request->password])) {
return redirect('/welcome');
}
return "Oooops something wrong happen";
}
this my login form
<form action="login" method="post">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<div class="form-group">
<input type="email" name="" value="" class="form-control" placeholder="Enter Your Email">
</div>
<div class="form-group">
<input type="password" name="" value="" class="form-control" placeholder="Enter Your password">
</div>
<div class="form-group">
<input type="submit" name="" value="login" class="btn btn-success btn-lg btn-block">
</div>
and my route
Route::post('/login', 'UserController#login');

Your form is wrong, your name values are empty, and you're missing the confirmation password field
<form action="login" method="post">
{{ csrf_field() }}
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Enter Your Email">
</div>
<div class="form-group">
<input type="password" name="passowrd" class="form-control" placeholder="Enter Your password">
</div> <div class="form-group">
<input type="password" name="passowrd_confirmation" class="form-control" placeholder="Enter Your password">
</div>
<div class="form-group">
<input type="submit" value="login" class="btn btn-success btn-lg btn-block">
</div>
</form>

Related

Message sending through session isn't showing

In my laravel-7 application I am sending custom message for invalid login in blade through controller. but message is not showing in blade. also tail me if I am doing anything wrong.
in blade
<div class="card-body">
#if(session()->has('message'))
<div class="alert alert-{{session('type')}}">
<li>{{session('message')}}</li>
</div>
#endif
<form action="{{route('login')}}" method="post" class="form">
#csrf
<div class="form-group">
<label for="email">Email address</label>
<input type="email" name="email" class="form-control" id="email" placeholder="Enter email" value="{{old('email')}}">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" class="form-control" id="password" placeholder="Password">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Login</button>
</div>
</form>
in auth controller
public function processlogin(Request $request)
{
$this->validate($request,[
'email'=>'required|email',
'password'=>'required|min:6',
]);
$credentials=$request->except(['_token']);
if (Auth::attempt($credentials)){
return redirect()->route('index');
}
$this->setErrorMessage('Invalid Credentials.');
return redirect()->back();
}
in controller
public function setErrorMessage($message):void
{
session()->flash($message);
session()->flash('type','danger');
}
You are not naming the flashed variable message. You are passing the value of $message as the first argument to flash which is the name of the key.
session()->flash('message', $message);

Laravel csrf_field() Is Blank

I am learning about Packages in Laravel 5.4 and ultimately I will upload them to github.
This is my directory structure :
laravel
-vendor
--student
---myPackage
----src
-----Views
------myView.blade.php
the myView.blade.php has a form in it, and a {{csrf_field()}} function call, but when I inspect the output in the browser, the value attribute of the hidden input <input name="_token" value="" type="hidden"> is empty.
How do I make this work ?
SOLUTION
Apparantly, I needed to make sure that the web middleware is in use
for my routes, so I changed Route::get('/Register/{group}',
'Student\myPackage\Http\User#create'); to
Route::get('/Register/{group}',
'Student\myPackage\Http\User#create')->middleware('web');
Route:
Route::get('/Register/{group}', 'Student\myPackage\Http\User#create');
Route::post('/Register/{group}', 'Student\myPackage\Http\User#store');
Controller:
public function create($group){
return view('StudentUser::app', ['group' => $group]);
}
public function store($group)
{
dd(request()->all());
}
Form:
<form class="form-horizontal" role="form" method="POST" action="/Register/{{$group}}">
<div class="tab-content">
<div id="ap-about" class="tab-pane active">
{!! csrf_token() !!}
<div class="form-group">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="" required autofocus>
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="" required>
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="button" class="btn btn-primary">
Next
</button>
</div>
</div>
</div>
<div id="ap-personal" class="tab-pane">
<div class="form-group">
<label for="address" class="col-md-4 control-label">Address</label>
<div class="col-md-6">
<input id="address" type="text" class="form-control" name="personal[]" value="" required autofocus>
</div>
</div>
<div class="form-group">
<label for="url" class="col-md-4 control-label">url</label>
<div class="col-md-6">
<input id="url" type="text" class="form-control" name="personal[]" value="" required autofocus>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</div>
</div>
</form>

laravel form model binding not working laravel 5.4

I have gone through similar posts on SO but nothing has worked for me and also not found relative answer. Even it is not updating data.
{!! Form::model($editClient, [ 'method' => 'PATCH','route' => ['clients.update', $editClient->id],'class' => 'form-horizontal', 'id'=>'edit-client' ]) !!}
#include('clients._form')
I am using form as partial
Route:
Route::resource('clients', 'ClientController');
Controller Method:
public function edit($id)
{
$editClient = User::findOrFail($id);
return view('clients.edit', compact('editClient'));
}
HTML:
<div class="form-group">
<label class="control-label col-sm-2" for="username">Username:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="email" name="user_name" placeholder="Enter Username">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pwd" name="password" placeholder="Enter password">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="contact">Contact Number: </label>
<div class="col-sm-10">
<input type="number" class="form-control" id="contact" name="contact" placeholder="Enter Contact Number">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
From the Laravel Collective docs for Form model binding (https://laravelcollective.com/docs/5.4/html#form-model-binding):
{{ Form::model($user, ['route' => ['user.update', $user->id]]) }}
You have $editClient whereas I think your model is probably $client

How to validate multiple value (Array of value ) in single Input (form) in codeigniter

this is the html part when i add more email id's only first email is being validated and rest of emails treat as normal even if they are not in proper
<form action="<?php echo base_url()?>index.php/EMail/show_email">
<div class="form-group">
<label for="exampleInputEmail1">To :</label>
<input type="email" name="toa[]" ng-model="to" placeholder="To" class=" tagsinput" value="ss" />
</div>
<div class="form-group">
<label for="exampleInputEmail1">Subject :</label>
<input type="text" class="form-control" ng-model="sub" name="suba" id="exampleInputEmail1" placeholder="Subject">
<div>{{sub}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">CC :</label>
<input type="text" class="form-control" ng-model="to" name="cca" id="exampleInputEmail1" placeholder="CC">
<div>{{to}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">BCC:</label>
<input type="text" class="form-control" name="bcca" id="exampleInputEmail1" placeholder="BCC">
</div>
<div class="form-group ">
<label for="ccomment" class="control-label">Message</label>
<textarea class="form-control " id="ccomment" name="msg" required></textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<input type="submit" onclick="mail()" class="btn btn-primary" value="Send"/>
<button type="submit" class="btn btn-Success">Draft</button>
</form>
this is my controller and "toa "is that field which i mentioned in the image
function show_email(){
$this->form_validation->set_rules("toa[]","To","valid_email");
$this->form_validation->set_rules("cca","CC ","valid_email");
$this->form_validation->set_rules("suba","Subject","required");
$this->form_validation->set_rules("bcca","bcc","valid_email");
$this->form_validation->set_rules("msg","Message","required");
if($this->form_validation->run()==FALSE){
$data["title"]="EMail";
$this->load->view('header',$data);
$this->load->view('sidebar');
$this->load->view('Mail/mail');
}else{
//finish
$ccdata=$this->input->post("cca");
$bccdata=$this->input->post("bcca");
$sub=$this->input->post("suba");
$ms=$this->input->post("msg");
$dataa["username"]="MyProject";
$dataa["msg"]=$ms;
$msg=$this->load->view('Email_Temp/mail',$dataa,TRUE);
$todata=explode(",",$data);
print_r($todata[0]);
//$this->SendEmail($todata,$ccdata,$bccdata,$msg,$sub);
}
}
[Image] this is the field (to) that i want to validate

TokenMismatchException in VerifyCsrfToken.php line 53: in laravel 5.1

Below is my form code
<div class="row">
<div class="form-group col-sm-12">
<input type="text" name="name" class="form-control" id="name" placeholder="Enter name ">
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<input type="email" name="email" class="form-control" id="email" placeholder="Enter email ">
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<input type="password" name="password" class="form-control" id="pwd" placeholder="Enter password">
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<input type="password" class="form-control" id="pwd" placeholder="Re-enter password">
</div>
<div class="row">
<div class="col-sm-6 ">
<input type="submit" class="btn btn-info" value="SIGNUP">
</div>
</div>
</form>
After submitting form it shows TokenMismatchException in VerifyCsrfToken.php line 53:
I am completely get frustrated due to this errror.
I also used token in the form and also tried to clear cache but still facing same problem
What will be the problem?
You need to include a hidden field in your Form with the csrf token.
In your form, include the below:
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">

Resources