0

我已经更改了auth.php文件,以便根据作者表对我的用户进行身份验证。但是当我运行路线时,我一直没有为你考虑。test

授权文件

<?php

return array(

    'driver' => 'eloquent',

    'model' => 'Author',

    'table' => 'authors',

    'reminder' => array(

        'email' => 'emails.auth.reminder', 'table' => 'password_reminders',

    ),

);

路由.php

Route::get('test', function() {
    $credentials = array('username' => 'giannis',
        'password' => Hash::make('giannis'));
    if (Auth::attempt($credentials)) {
        return "You are a user.";
    }
    return "No account for you";
});

作者TableSeeder.php

<?php

class AuthorsTableSeeder extends Seeder {

    public function run()
    {
        // Uncomment the below to wipe the table clean before populating
      DB::table('authors')->delete();

      $authors = array(
         [ 
         'username' => 'giannis',
         'password' => Hash::make('giannis'),
         'name' => 'giannis',
         'lastname' => 'christofakis'],
         [
         'username' => 'antonis',
         'password' => Hash::make('antonis'),
         'name' => 'antonis',
         'lastname' => 'antonopoulos']
         );

        // Uncomment the below to run the seeder
      DB::table('authors')->insert($authors);
  }

}

附录


我在另一篇文章中看到您必须实现UserInterface RemindableInterface接口。但结果是一样的。

作者.php

<?php

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

class Author extends Eloquent implements UserInterface, RemindableInterface {

    protected $guarded = array();

    public static $rules = array();

    public function posts() {
        return $this->hasMany('Post');
    }

    /**
         * Get the unique identifier for the user.
         *
         * @return mixed
         */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

        /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
        public function getReminderEmail()
        {
            return "giannis@hotmail.com";
        }
    }
4

1 回答 1

1

使用时不需要散列密码,Auth::attempt();因此请Hash::make从路线中删除

Route::get('test', function() {
$credentials = array('username' => 'giannis',
    'password' => 'giannis');
if (Auth::attempt($credentials)) {
    return "You are a user.";
}
return "No account for you";

});

它会像魅力一样发挥作用!

于 2013-07-01T14:21:01.333 回答