1

フェローシップのために 1 年前の Laravel プロジェクトを使い始めたところですが、進行を妨げる大きなバグが進行中です。どんな助けでも大歓迎です。以下ストーリー。

Laravel が起動して実行され、ログインしようとすると、次のエラーが表示されます。

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)

これはhttp://laravel.com/docs/upgrade#upgrade-4.1.26で修正できると信じていたので、提案どおりに次の行をユーザーに追加しました。

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

これでエラーは解消されましたが、まだログインできません。正しい情報を使用しますが、ログイン ページにリダイレクトされるようです。さらに調査したところ、データベースに [b]remember_token[/b] フィールドが必要な場合があることがわかりました。これを追加して、次を追加して再移行しようとしました:

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

しかし、それはこのスタックトレースを生成しました:

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/

[編集 2014-09-16, 07:05: ウォッチャーの回答を試しました] 昨夜のウォッチャーの回答の後、私はそれらのソリューションを置き換えて使用しようとしました

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

移行はエラーをスローしなくなりましたが、ログインは引き続きハングします。rememberTokenまた、Laravel は次の構文を使用することを推奨していることを指摘しておく必要があります。

私のログインルート

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

およびコントローラーメソッド

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