1

I just started working with a year old Laravel project for my fellowship and a major bug inhibiting progress is in the way. Any help would be greatly appreciated. Story below.

Once Laravel is up and running and I try to log in, I get this error:

Class User contains 3 abstract methods and must therefore be declared abstract or
implement the remaining methods 
(Illuminate\Auth\UserInterface::getRememberToken, 
Illuminate\Auth\UserInterface::setRememberToken,
Illuminate\Auth\UserInterface::getRememberTokenName)

I believed this could be fixed via http://laravel.com/docs/upgrade#upgrade-4.1.26 and so I added the following lines to my User as suggested:

public function getRememberToken(){ return $this->remember_token; }
public function setRememberToken($value){ $this->remember_token = $value; }
public function getRememberTokenName(){ return 'remember_token'; }

This got rid of the error but I still cannot log in. I'll use the correct information but it seems to redirect me back to the login page. Upon further research, I discovered that I may need to have a [b]remember_token[/b] field in my database. I attempted to add this and remigrate by adding:

$table->rememberToken(); 
[edit 2014-09-16, 07:05: added parens. they were in my code but forgotten in the post]

But that produced this stacktrace:

PHP Fatal error:  Call to undefined method Illuminate\Database\Schema\Blueprint::rememberToken() in /vagrant/www/vfamatching.dev/app/database/migrations/2013_11_01_033240_create_users_table.php on line 24
PHP Stack trace:
PHP   1. {main}() /vagrant/www/vfamatching.dev/artisan:0
PHP   2. Symfony\Component\Console\Application->run() /vagrant/www/vfamatching.dev/artisan:59
PHP   3. Symfony\Component\Console\Application->doRun() /vagrant/www/vfamatching.dev/vendor/symfony/console/Symfony/Component/Console/Application.php:121
PHP   4. Symfony\Component\Console\Application->doRunCommand() /vagrant/www/vfamatching.dev/vendor/symfony/console/Symfony/Component/Console/Application.php:191
PHP   5. Illuminate\Console\Command->run() /vagrant/www/vfamatching.dev/vendor/symfony/console/Symfony/Component/Console/Application.php:893
PHP   6. Symfony\Component\Console\Command\Command->run() /vagrant/www/vfamatching.dev/vendor/laravel/framework/src/Illuminate/Console/Command.php:96
PHP   7. Illuminate\Console\Command->execute() /vagrant/www/vfamatching.dev/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:244
PHP   8. Illuminate\Database\Console\Migrations\MigrateCommand->fire() /vagrant/www/vfamatching.dev/vendor/laravel/framework/src/Illuminate/Console/Command.php:108
PHP   9. Illuminate\Database\Migrations\Migrator->run() /vagrant/www/vfamatching.dev/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:67
PHP  10. Illuminate\Database\Migrations\Migrator->runMigrationList() /vagrant/www/vfamatching.dev/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:84
PHP  11. Illuminate\Database\Migrations\Migrator->runUp() /vagrant/www/vfamatching.dev/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:113
PHP  12. CreateUsersTable->up() /vagrant/www/vfamatching.dev/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:137
PHP  13. Illuminate\Support\Facades\Schema::create() /vagrant/www/vfamatching.dev/app/database/migrations/2013_11_01_033240_create_users_table.php:25
PHP  14. Illuminate\Support\Facades\Facade::__callStatic() /vagrant/www/vfamatching.dev/app/database/migrations/2013_11_01_033240_create_users_table.php:25
PHP  15. Illuminate\Database\Schema\Builder->create() /vagrant/www/vfamatching.dev/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:209
PHP  16. CreateUsersTable->{closure:/vagrant/www/vfamatching.dev/app/database/migrations/2013_11_01_033240_create_users_table.php:15-25}() /vagrant/www/vfamatching.dev/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:91
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Call to undefined method Illuminate\\Database\\Schema\\Blueprint::rememberToken()","file":"\/vagrant\/www\/vfamatching.dev\/app\/database\/migrations\/2013_11_01_033240_create_users_table.php","line":24}}vagrant@devbox:/vagrant/www/

[edit 2014-09-16, 07:05: tried watcher's answer] After watcher's answer last night, I have tried using their solution by replacing

$table->rememberToken(); with
$table->string('remember_token', 100);

The migration no longer throws an error but the login still hangs. Also, I should point out that Laravel recommends using the rememberToken syntax

My login route

Route::get('login', array('as' => 'login', function () { return View::make('login'); }))->before('guest');
Route::post('login', 'UsersController@login');

and controller method

public function login() 
{ 
    $user = array(
        'email' => Input::get('email'),
        'password' => Input::get('password')
    );   
    if (Auth::attempt($user)) {
        Auth::user()->login();
        Auth::user()->lastLogin = Carbon::now();
        Auth::user()->save();
        if (Session::has('returnUrl'))
        {
            $intendedDestination = Session::get('returnUrl');
            Session::forget('returnUrl');
            return Redirect::to($intendedDestination)
            ->with('flash_success', 'You are successfully logged in.');
        }
        return Redirect::to('/')
            ->with('flash_success', 'You are successfully logged in.');
    }
    // authentication failure! lets go back to the login page
    return Redirect::route('login')
        ->with('flash_error', 'Your username/password combination was incorrect.')
        ->withInput();
}
4

2 回答 2

2

'remember_token'只是一个varchar字段,应该像迁移中的任何其他字段一样创建:

$table->string('remember_token', 100)->nullable();

更新

作为对您的评论的回应,您是正确的,架构构建器文档确实允许该rememberToken方法,有趣的是升级指南没有提及它。它仅在 Laravel v4.2 及更高版本中可用,在撰写本文时,它只不过是上述代码的别名:

// File: /vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php
/**
 * Adds the `remember_token` column to the table.
 *
 * @return \Illuminate\Support\Fluent
 */
public function rememberToken()
{
    return $this->string('remember_token', 100)->nullable();
}

如果您使用的是 4.2 或更高版本,我会使用rememberToken函数而不是string函数来定义列,以防上面的函数定义在任何未来版本中发生更改。

至于您的登录尝试“挂起”,请使用相关的控制器方法更新您的问题,我也许可以进一步帮助您。

于 2014-09-16T01:27:38.123 回答
0

也许这只是一个小错误,rememberToken 是一个方法,应该这样调用:

$table->rememberToken();
于 2014-09-16T07:50:44.070 回答