Php 为什么在Laravel 5.3中Auth::trunt总是返回false?

Php 为什么在Laravel 5.3中Auth::trunt总是返回false?,php,authentication,laravel-5.3,Php,Authentication,Laravel 5.3,我是新来的。我尝试在Laravel 5.3中使用多个Auth,我的Auth.php文件是: <?php return [ */ 'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ], 'guards' => [ 'web' => [ 'driver' => 'session',

我是新来的。我尝试在Laravel 5.3中使用多个Auth,我的Auth.php文件是:

<?php

return [

    */

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],

        'courier' => [
            'driver' => 'session',
            'provider' => 'couriers',
        ],

        'client' => [
            'driver' => 'session',
            'provider' => 'clients',
        ]
    ],

    'providers' => [
        'couriers' => [
            'driver' => 'eloquent',
            'model' => App\Courier::class,
        ],

        'clients' => [
            'driver' => 'eloquent',
            'model' => App\Client::class,
        ],

        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ]
    ],

    'passwords' => [
        'couriers' => [
            'provider' => 'couriers',
            'table' => 'password_resets',
            'expire' => 60,
        ],

        'clients' => [
            'provider' => 'clients',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];
当更新快递时,在我的控制器中,我有:

public function update(Request $request, $id) {

        $fieldsCourier = $request->all();
        $courier = Courier::find($id);

        if( isset($fieldsCourier['password']) )
            $fieldsCourier['password'] = bcrypt($fieldsCourier['password']);

        if( $courier->update($fieldsCourier) )
            $courier = Courier::find($id);

    }
我有一个名为authenticate的方法,但方法尝试总是返回false(无效的\u凭据)。即使如此,请发送有效的凭据。。这是我的代码:

public function authenticate(Request $request) {
        $credentials = $request->only('email', 'password');

        try {
            if ( auth()->guard('courier')->attempt($credentials) ){
                $user = Auth::guard('courier')->user();
            } else {
                return response()->json(['error' => 'invalid_credentials'], 401);
            }
        } catch (JWTException $e) {
            return response()->json(['error' => 'could_not_create_token'], 500);
        }

        return response()->json(compact('user'));
    }

我不知道我做错了什么。我做错什么了吗?

您已经在型号和控制器上对密码加密了两次

只需移除其中一个

e、 g:不要在控制器上使用
bcrypt
,因为您已经在您的型号上使用了
bcrypt

public function authenticate(Request $request) {
        $credentials = $request->only('email', 'password');

        try {
            if ( auth()->guard('courier')->attempt($credentials) ){
                $user = Auth::guard('courier')->user();
            } else {
                return response()->json(['error' => 'invalid_credentials'], 401);
            }
        } catch (JWTException $e) {
            return response()->json(['error' => 'could_not_create_token'], 500);
        }

        return response()->json(compact('user'));
    }