call_user_func_array() 期望参数 1 是一个有效的回调,类 'Illuminate\Auth\Guard' 没有方法 'attempt' - Laravel 中的 Auth

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23351707/
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 09:26:30  来源:igfitidea点击:

call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Auth\Guard' does not have a method 'attemp' - Auth in Laravel

phpauthenticationlaravellaravel-4

提问by TuGordoBello

I'm trying to do a basic authentication, and I have many problems, the main one is this

我正在尝试进行基本身份验证,但遇到了很多问题,主要是这个

enter image description here

在此处输入图片说明

This error when I send the form and try to authenticate

当我发送表单并尝试进行身份验证时出现此错误

blade

刀刃

{{ Form::open(array('url' => 'usuario')) }}

                    <input type="text" class="text"  id="email" name="email" placeholder="Correo" {{(Input::old('email')) ? 'value ="'. Input::old('email').'"' : '' }}>
                    <p>{{ $errors->first('email') }}</p>
                    <input type="text" class="text"  id="password" name="password" placeholder="Contrase?a" >
                    <p>{{ $errors->first('password') }}</p>


                {{ Form::submit('Ingresar', array('class' => 'bg1')) }}
{{ Form::close() }}

Route

路线

Route::post('usuario', array('as' => 'usuario', 'uses' => 'UsuarioController@doLogin'));

Model

模型

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class Usuario extends Eloquent implements UserInterface, RemindableInterface{
protected $table = 'Usuario';
protected $primaryKey = 'idUsuario';
protected $hidden = array('Contrasena');
protected $fillable = array(
                        'Nombre',
                        'Apellido',
                        'Tipo',
                        'Contrasena',
                        'Correo',
                        'Fono',
                        'Foto'
                        );
}

Controller

控制器

class UsuarioController extends BaseController{

public function doLogin(){
    $rules = array(
                    'email' => 'required|email',
                    'password' => 'required'
                    );
    $validator = Validator::make(Input::all(), $rules);
    if($validator->fails()){
        return Redirect::to('usuario')->withErrors($validator)->withInput(Input::except('password'));
    }else{

        $userdata = array(
            'Correo' => Input::get('email'),
            'Password' => Input::get('password')
            );

        if(Auth::attemp($userdata)){
            return View::make('hello');
        }else{
            return Redirect::to('usuario');
        }

    }
}
}

Auth

认证

'driver' => 'database',
'model' => 'Usuario',
'table' => 'Usuario',

please, how can I fix it?

请问,我该如何解决?

回答by The Alpha

Because attempshould be attempt:

因为attemp应该是attempt

if(Auth::attemp($userdata))

Should be:

应该:

if(Auth::attempt($userdata))