简体   繁体   English

如何使用laravel auth?

[英]How to use laravel auth?

Good day. 美好的一天。 I'm trying to use laravel auth . 我正在尝试使用laravel auth But i'm bit confused. 但是我有点困惑。

I'm already Login and Register. 我已经登录并注册了。

Here is my login process 这是我的登录过程

public function index(){

   if(!Auth::check()){
        return view::make("Login");
     }else{
        dd(Auth::user());
    }
}
    function loginproses(Request $request){
        extract(Maincontroller::populateform());    
         $a = Loginmodel::where('username',$username)
                    ->where('password',md5($password))
                    ->first();
            if($a === NULL){ 
                return redirect('/')->with('status', 'Username atau Password salah');
            }else{

            $userdata = array(
                    'username' =>$username
                );

           if(Auth::attempt($userdata)){
                return redirect('/');
           }
        }
    }

I'm using Userlogin as my table so i change this 我正在使用Userlogin作为表格,因此我将其更改

'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Loginmodel::class,
            'table' => 'Userlogin'
        ],

but the problem after the login. 但是登录后出现问题。 I get this error 我得到这个错误

Argument 1 passed to Illuminate\\Auth\\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\\Contracts\\Auth\\Authenticatable, instance of App\\Loginmodel given, called in D:\\xampp\\htdocs\\sitestarter\\vendor\\laravel\\framework\\src\\Illuminate\\Auth\\SessionGuard.php on line 380 and defined 传递给Illuminate \\ Auth \\ EloquentUserProvider :: validateCredentials()的参数1必须是Illuminate \\ Contracts \\ Auth \\ Authenticatable的实例,是给定的App \\ Loginmodel实例,在D:\\ xampp \\ htdocs \\ sitestarter \\ vendor \\ laravel \\ framework中调用\\ src \\ Illuminate \\ Auth \\ SessionGuard.php在第380行并已定义

how can i fix it ? 我该如何解决?

when using google for searching how to login in laravel i always see Laravel auth . 当使用谷歌搜索how to login in laravel我总是看到Laravel auth Then do i really need to use Laravel Auth ? 那我真的需要使用Laravel Auth吗? and do really need to use the auth controller ? 真的需要使用auth控制器吗?

Is your Loginmodel extend Authenticatable like 您的Loginmodel是否扩展了Authenticatableable之类的

use Illuminate\\Foundation\\Auth\\User as Authenticatable; 使用Illuminate \\ Foundation \\ Auth \\ User作为Authenticateable; use Illuminate\\Database\\Eloquent\\Model; 使用Illuminate \\ Database \\ Eloquent \\ Model;

class Loginmodel extends Authenticatable { } Loginmodel类扩展了Authenticateable {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM