topic description
validate verification class, why does it have different effects under different controllers, and use auth"s own login registration function
my version is laravel5.4
sources of topics and their own ideas
related codes
/ / Please paste the code text below (do not replace the code with pictures)
this is / app/Http/Controllers/Auth/LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;//requestvalidateLogin
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
// protected $redirectTo = "/home";
protected function redirectTo()
{
return route("home") ;
}
/*
* protected validateLogin
* @param \Illuminate\Http\Request $request
*
*/
protected function validateLogin(Request $request)
{
$attributes = array(
"required" => ":attribute ",
"between" => ":attribute :min :max ",
"string"=>":attribute ",
"email"=>":attribute ",
"max"=>":attribute ",
"min"=>":attribute ",
"confirmed"=>":attribute foo_confirmation passwordpassword_confirmation ",
"unique"=>":attribute "
);
$message= array(
"email"=>"",
"password"=>""
);
//validaterequest
$this->validate($request, [
"email" => "required|string|email|min:10", //unique:users,,
"password" => "required|string",
],$attributes,$message);
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//exceptlogout logout
$this->middleware("guest")->except("logout");
}
public function showLoginForm()
{
return view("home.home_login");
}
}
=
this is / app/Http/Controllers/Auth/RegisterController.php
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* ,use RedirectsUsers
*
* @return \Illuminate\Http\Response
*/
public function showRegistrationForm()
{
return view("home.home_register");
}
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = "/home";
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//,RedirectIfAuthenticated
$this->middleware("guest");
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
$attributes = array(
"required" => ":attribute ",
"between" => ":attribute :min :max ",
"string"=>":attribute ",
"email"=>":attribute ",
"max"=>":attribute ",
"confirmed"=>":attribute foo_confirmation passwordpassword_confirmation ",
"unique"=>":attribute "
);
$message= array(
"name"=>"",
"email"=>"",
"password"=>""
);
$validator= Validator::make($data, [
"name" => "required|string|max:255",
"email" => "required|string|email|max:255|unique:users", //users,,,
//unique:table,column,except,idColumn
//columncolumn
"password" => "required|string|min:6|confirmed",
// confirmed foo_confirmation password password_confirmation
],$attributes,$message);
return $validator;
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
"name" => $data["name"],
"email" => $data["email"],
"password" => bcrypt($data["password"]),
]);
}
}
what result do you expect? What is the error message actually seen?
Why the login login page prompts an error but does not show a custom error
Register