Closed zettich closed 5 years ago
@zettich I'll check it. Now as quick solution you can remove namespace from group and use following construction:
use App\Http\Controllers\AuthController;
.....
Route::get('/route', AuthController::class . '@action');
I'll let you know when the bug is fixed
@zettich Could you please attach Laravel version? I cannot reproduce it on Laravel 5.6.
Do I reproduce it correctly?
\App\Http\Controllers\SomeController
<?php
namespace App\Http\Controllers;
class SomeController extends Controller
{
public function action()
{
return response();
}
}
routes.php
Route::group(['namespace' => 'App\Http\Controllers'], function() {
Route::get('/route', 'SomeController@action');
});
\App\Providers\RouteServiceProvider
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
protected $namespace = '';
public function boot()
{
parent::boot();
}
public function map()
{
Route::middleware('api')
->group(base_path('routes/api.php'));
}
}
Please check here namespace. If you will set it twice(here and in Route::group) you will get wrong result namespace of controller. But this is not a bug of laravel-swagger
Test:
public function testBugReproduce()
{
$response = $this->json('get', '/route');
$response->assertStatus(Response::HTTP_OK);
}
In this configuration on Laravel 5.6
$controller = $this->request->route()->getActionName();
returns App\Http\Controllers\SomeController@action
@zettich Is it still actual?
@zettich Close issue because of inactivity.
RESTful Route in Route Group with Namespace parameter, for example:
Route::group(['namespace' => 'App\Http\Controllers'], function() { Route::get('/route', 'SomeController@action'); });
When I'm running PHPUnit tests an exception occurs:
[2018-05-23 18:58:14] testing.ERROR: Class AuthController does not exist {"userId":1,"email":"abigail.mohr@gmail.com","exception":"[object] (ReflectionException(code: -1): Class SomeController does not exist at /var/www/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:767)
An error occurs in:
#5 /var/www/app/vendor/ronasit/laravel-swagger/src/Services/SwaggerService.php(429): app('SomeController')
Because a controller class name that detects in function getConcreteRequest does't include parent route group namespace.