在 Laravel 5.3 中找不到特征“Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39655328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:30:19  来源:igfitidea点击:

Trait 'Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers' not found in Laravel 5.3

phplaravellaravel-5.3

提问by Poldo

How to solve this problem? I alreay tried to use all the solution from the net and i tried also to use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers but none of them works?. If anyone knows how to solve this please help me. I want to get rid of this error. Thanks in advance

如何解决这个问题呢?我已经尝试使用网络上的所有解决方案,我也尝试使用 Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers 但它们都不起作用?。如果有人知道如何解决这个问题,请帮助我。我想摆脱这个错误。提前致谢

<?php

namespace App\Http\Controllers\Auth;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Support\Facades\Validator;   
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;

use Illuminate\Routing\Controller as BaseController;
use Theme;
use Auth;
use App\Login;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use App\Http\Controllers\Auth\RegisterController;
class LoginController extends BaseController
{

/*
|--------------------------------------------------------------------------
| 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 AuthenticatesAndRegistersUsers, ThrottlesLogins;

/**
 * Where to redirect users after login / registration.
 *
 * @var string
 */
protected $redirectTo = '/';


/**
 * Create a new controller instance.
 *
 * @return void
 */

public function __construct()
{
    $this->middleware('guest', ['except' => 'logout']);
}


public function signin(){

    if(Auth::check()){

        return Redirect::to('/');

    }else{
        $theme = Theme::uses('default')->layout('default');
        return $theme->of('login.sign-in')->render();
    }

}



public function login(){


    $data = array(
        'email' => Input::get('email'),
        'password' => Input::get('password')
    );

   $validator= RegisterController::validator($data);

    if($validator){
        return Redirect::to('/login')->withErrors([$validator->errors()->all() ]);
    }else{
        return Redirect::to('/');
    }
}




      //  RegisterController::create($data);

       // Login::Insert($data);
      //  $checkuser = Login::Login($data);





function logout(){
    Auth::logout();
    return Redirect::to('login');
 }

 }

回答by AddWeb Solution Pvt Ltd

I think the Laravel 5.3 package does not have that trait. Please check here.

我认为 Laravel 5.3 包没有那个特性。请检查这里

EDIT:

编辑:

You need to make a few changes to how new users are validated and created because of AuthenticatesAndRegistersUsers no longer exist into laravel 5.3

由于 AuthenticatesAndRegistersUsers 在 laravel 5.3 中不再存在,您需要对如何验证和创建新用户进行一些更改

So you need to make a change:

所以你需要做出改变:

1No need to pass the Guard and Registrar instances to the base constructor. Remove these dependencies entirely from your controller's constructor.

2No need to use App\Services\Registrar class which is used in Laravel 5.0 just copy and paste your validator and create method from this class directly into your AuthController.

1无需将 Guard 和 Registrar 实例传递给基本构造函数。从控制器的构造函数中完全删除这些依赖项。

2无需使用 Laravel 5.0 中使用的 App\Services\Registrar 类,只需将您的验证器和 create 方法从此类直接复制并粘贴到您的 AuthController 中。

Make sure that the import the Validator facade and your User model at the top of your AuthController.

确保在 AuthController 的顶部导入验证器外观和用户模型。