0

サンプル Sentinel メソッドを試しています。ユーザーを登録し、ユーザー名を使用して認証したいだけです。

メール属性をユーザー名に置き換えてユーザーテーブルを変更し、移行を行いました。これが私のユーザーテーブルです。

Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('username');
        $table->string('password');
        $table->text('permissions')->nullable();
        $table->timestamp('last_login')->nullable();
        $table->timestamps();

        $table->engine = 'InnoDB';
        $table->unique('username');
    });

以下のメソッドを呼び出してサンプル ユーザーを登録しようとすると、エラーが発生します。

コード:

$credentials = [
   'username' => 'testuser123',
   'password' => '123'
];

$activation =  Sentinel::registerAndActivate($credentials);

エラー:

InvalidArgumentException in IlluminateUserRepository.php line 271:
No [login] credential was passed.
in IlluminateUserRepository.php line 271
at IlluminateUserRepository->validateUser(array('username' => 'testuser123', 'password' => '123')) in IlluminateUserRepository.php line 154
at IlluminateUserRepository->validForCreation(array('username' => 'testuser123', 'password' => '123')) in Sentinel.php line 164
at Sentinel->register(array('username' => 'testuser123', 'password' => '123'), true) in Sentinel.php line 191
at Sentinel->registerAndActivate(array('username' => 'testuser123', 'password' => '123')) in Sentinel.php line 97
at Sentinel::__callStatic('registerAndActivate', array(array('username' => 'testuser123', 'password' => '123'))) in AuthenticationController.php line 196
at Sentinel::registerAndActivate(array('username' => 'testuser123', 'password' => '123')) in AuthenticationController.php line 196
at AuthenticationController->testFunction()
at call_user_func_array(array(object(AuthenticationController), 'testFunction'), array()) in Controller.php line 246
at Controller->callAction('testFunction', array()) in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(AuthenticationController), object(Route), 'testFunction') in ControllerDispatcher.php line 107
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
at ControllerDispatcher->callWithinStack(object(AuthenticationController), object(Route), object(Request), 'testFunction') in ControllerDispatcher.php line 67
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\AuthenticationController', 'testFunction') in Route.php line 204
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 701
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 703
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 670
at Router->dispatchToRoute(object(Request)) in Router.php line 628
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
at require_once('/home/pranavaghanan/Documents/GitHub Projects/To Integrate For Release 1/SEP/public/index.php') in server.php line 21

問題を修正する方法はありますか? ありがとう。

4

1 に答える 1

2

問題は、credentialsパラメータで必要emailないことusernameです。

したがって、次のように変更して agian を試してください。

$credentials = [
   'email'    => 'testuser123',
   'password' => '123'
];

username認証に電子メールの代わりに使用する必要がある場合は、この回答をお読みください。

于 2015-11-04T14:32:35.160 に答える