Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

laravel 9 api routes error #186

Closed
dangermember opened this issue Sep 8, 2022 · 7 comments · Fixed by #187
Closed

laravel 9 api routes error #186

dangermember opened this issue Sep 8, 2022 · 7 comments · Fixed by #187

Comments

@dangermember
Copy link

the command i used
php artisan create:api-scaffold User --with-api-resource

the use at the top of api.php
use App\Api\Http\Controllers\Api\Api\UsersController;
supposed to be
use App\Http\Controllers\Api\UsersController;

data from my composer.json
"php": "^8.0.2",
"laravel/framework": "^9.19",
"crestapps/laravel-code-generator": "^2.4",

@MikeAlhayek
Copy link
Collaborator

Are you using the default setting or have you customized the settings?

@dangermember
Copy link
Author

My config
'files_upload_path' => 'uploads',
'datetime_out_format' => 'Y-m-d H:i:s',
'template'=>'default'

@MikeAlhayek
Copy link
Collaborator

I'll have to look more at the code. But can you try adding this to your config?

'api_controllers_path' => 'Http/Controllers',

Does that fix it?

@dangermember
Copy link
Author

First i would like to thank you for your fast response.

when using config:
'api_controllers_path' => 'Http/Controllers',
the output is:

use App\Http\Controllers\UsersController;

Route::group([
    'prefix' => 'users',
], function () {
    Route::get('/', [UsersController::class, 'index'])
         ->name('api.users.user.index');
    Route::get('/show/{user}',[UsersController::class, 'show'])
         ->name('api.users.user.show');
    Route::post('/', [UsersController::class, 'store'])
         ->name('api.users.user.store');    
    Route::put('user/{user}', [UsersController::class, 'update'])
         ->name('api.users.user.update');
    Route::delete('/user/{user}',[UsersController::class, 'destroy'])
         ->name('api.users.user.destroy');
});

when using config:
'api_controllers_path' => 'Http/Controllers/API',
the output is:

use App\API\Http\Controllers\API\API\UsersController;
Route::group([
    'prefix' => 'users',
], function () {
    Route::get('/', [API\UsersController::class, 'index'])
         ->name('api.users.user.index');
    Route::get('/show/{user}',[API\UsersController::class, 'show'])
         ->name('api.users.user.show');
    Route::post('/', [API\UsersController::class, 'store'])
         ->name('api.users.user.store');    
    Route::put('user/{user}', [API\UsersController::class, 'update'])
         ->name('api.users.user.update');
    Route::delete('/user/{user}',[API\UsersController::class, 'destroy'])
         ->name('api.users.user.destroy');
});

while the expected output is:

use App\Http\Controllers\API\UsersController;
Route::group([
    'prefix' => 'users',
], function () {
    Route::get('/', [UsersController::class, 'index'])
         ->name('api.users.user.index');
    Route::get('/show/{user}',[API\UsersController::class, 'show'])
         ->name('api.users.user.show');
    Route::post('/', [UsersController::class, 'store'])
         ->name('api.users.user.store');    
    Route::put('user/{user}', [UsersController::class, 'update'])
         ->name('api.users.user.update');
    Route::delete('/user/{user}',[UsersController::class, 'destroy'])
         ->name('api.users.user.destroy');
});

@MikeAlhayek
Copy link
Collaborator

Not sure. I'll test it and respond with my findings.

MikeAlhayek added a commit that referenced this issue Sep 9, 2022
MikeAlhayek added a commit that referenced this issue Sep 9, 2022
@MikeAlhayek
Copy link
Collaborator

MikeAlhayek commented Sep 9, 2022

@dangermember this fix is part of v2.4.9 now. Please update and let me know if that fixed your issue

@dangermember
Copy link
Author

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants