Laravel - 使用简单的auth驱动程序'未初始化的字符串偏移量:0'

时间:2013-01-11 18:47:25

标签: laravel

您好我一直在研究Laravel框架,但无法让这个auth驱动程序工作!返回:

未处理的例外

Message:

Uninitialized string offset: 0
Location:

C:\wamp\www\site\laravel\auth\drivers\eloquent.php on line 39

我有一个登录控制器:

class Login_Controller extends Base_Controller {

    public $restful = true;

    public function post_index()
    {
        $username = Input::get('username');
        $password = Input::get('password');

        if ( Auth::attempt($username, $password) )
        {
            return Redirect::to('home');
        }
        else
        {
            return Redirect::to('login')->with('login_errors', true);
        }

    }

    public function get_index() {

        return View::make('page.login');

    }

}

我有'username' => 'username',

在行名称

的auth.php中

还有其他人遇到过这个吗?

问候

菲尔

1 个答案:

答案 0 :(得分:0)

好的发现了,需要通过数组将凭证传递给attempt方法:

<?php

class Login_Controller extends Base_Controller {

    public $restful = true;

    public function post_index()
    {
        $username = Input::get('username');
        $password = Input::get('password');

        if ( Auth::attempt( array( 'username' => $username, 'password' => $password ) ) )
        {
            return Redirect::to('home');
        }
        else
        {
            return Redirect::to('login')->with('login_errors', true);
        }

    }

    public function get_index() {

        return View::make('page.login');

    }

}