我一直在"不匹配"使用我的laravel手动登录进行身份验证 这是我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Admin;
use Input;
use Validator;
use Auth;
class CobaLogin extends Controller
{
public function index(){
return view('adminlogin');
}
public function username(){
return 'username';
}
public function doLogin(Request $request){
$username = $request ->input('username');
$password = $request -> input('password');
if(Auth::attempt(['username' => $username, 'password' => $password])){
echo "yes match";
}else{
echo "not match";
}
}
}
这是我在admin表中的模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Admin extends Authenticatable{
protected $table = "admin";
}
这是我的路线
Route::get('loginadmin', 'CobaLogin@index');
Route::post('dologin', 'CobaLogin@doLogin');
这是我的登录刀片文件
<div class="wrapper">
<form class="form-signin" action="{{ url('dologin')}}" method="POST">
{{ csrf_field() }}
<br/><h2 class="form-signin-heading text-center">ADMIN LOGIN</h2>
<input type="text" class="form-control" name="username" placeholder="Email Address" required="" autofocus="" />
<input type="password" class="form-control" name="password" placeholder="Password" required=""/>
<label class="checkbox">
<input type="checkbox" value="remember-me" id="rememberMe" name="rememberMe"> Remember me
</label>
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
</form>
</div>
这是我的auth.php文件
'providers' => [
'admin' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
这是我的注册函数
public function store(Request $request){
$data=Input::except(array('_token'));
// var_dump($data);
$rule=array(
'username' => 'required|unique:admin',
'password' => 'required|min:6',
'cpassword' => 'required|same:password',
'email' => 'required|email',
);
$message=array(
'username' => 'This username already taken',
'cpassword.min'=>'the password must at least 6 characters',
'cpassword.same'=>'the password and confirm password must same',
);
$validator= validator::make($data,$rule,$message);
if($validator->fails()){
return redirect() -> to('adduser')->withErrors($validator);
}else{
$tambah = new Admin();
$tambah->username = $request['username'];
$tambah->password = Hash::make($request['password']);
$tambah->email = $request['email'];
$tambah->alamat = $request['alamat'];
$tambah->lebih = $request['lebih'];
$tambah->save();
return redirect()->to('users')->with('success','Your Data Has Been Added');
}
}
这是 my database table 我使用Hash加密密码,我认为注册没什么问题,我错过了什么?
我一直在&#34;不匹配&#34;作为答案来自
请帮助掌握
答案 0 :(得分:0)
默认情况下,Laravel使用User
模型进行身份验证。您可以通过修改config/auth.php
:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],