Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mecjos's avatar

PUT Route Deosn't work with Custom Api Guard (Passport)

Hi. I have a personal access client to produce access tokens for my manufacturers and customers tables. And added provider and api-guarda as follows;

Providers in auth/config

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
        'customers' => [
            'driver' => 'eloquent',
            'model' => App\Models\Customer::class,
        ],
        'manufacturers' => [
            'driver' => 'eloquent',
            'model' => App\Models\Manufacturer::class,
        ]
    ],

Guards:

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

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
            'hash' => false,
        ],

        'api-customer' => [
            'driver' => 'passport',
            'provider' => 'customers',
            'hash' => false,
        ],

        'api-manufacturer' => [
            'driver' => 'passport',
            'provider' => 'manufacturers',
            'hash' => false,
        ],
    ],

And added hasApiTokenclass into related models. I added that client's routes as follows:

Route::middleware('auth:api-manufacturer')->group(function () {
    Route::get('jobs/outsource/{orderId}', 'JobController@outsourceJobs');
    Route::get('outsource/states', 'StateController@index');
    Route::get('outsource/cad/{id}', 'CadController@download');
    Route::get('job/stateupdate/{id}','JobController@update');
});

The problem is when I add put route in order to update record it retruns unauthanticated error. Only get routes are working but when I check routes with php artisan route:listcommand I can see routes in correct way. Where is the problem? Why that new api guard doesn't work like predefined api:auth guard? Thank you.

0 likes
1 reply
MuhammadHHassan's avatar

@mecjos that's because you defined the update route with get method. It should be

Route::middleware('auth:api-manufacturer')->group(function () {
    Route::put('job/stateupdate/{id}','JobController@update');
});

Please or to participate in this conversation.