dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.33k stars 1.25k forks source link

Incompatibility with Laravel 5.6? "Call to undefined method Dingo\Api\Routing\Route::getDomain()" #1557

Closed ldanielduarte closed 6 years ago

ldanielduarte commented 6 years ago
Q A
Bug? maybe
New Feature? no
Framework Laravel
Framework version 5.6.20
Package version 1.0.0-beta8
PHP version 7.16

Actual Behaviour

When running: app('Dingo\Api\Routing\UrlGenerator')->version('v1')->route('route.alias', ['parameter']) I get the following error Error : Call to undefined method Dingo\Api\Routing\Route::getDomain()

Expected Behaviour

The route must be correctly generated.

Steps to Reproduce

config/app.php:

return [
    'providers' => [
        Dingo\Api\Provider\LaravelServiceProvider::class,
        ...,
    ],
    'aliases' => [
        'Route' => Illuminate\Support\Facades\Route::class,
        'DingoApi' => Dingo\Api\Facade\API::class,
        'DingoRoute' => Dingo\Api\Facade\Route::class,
        ...,
    ],
];

app/Providers/RouteServiceProvider.php:

    protected function mapApiRoutes()
    {
        \Route::prefix('api')->group(base_path('routes/api.php'));
    }

routes/api.php:

$api = app('Dingo\Api\Routing\Router');
$api->version(
    'v1',
    [
        'namespace' => 'App\Http\Controllers\Api\V1',
    ],
    function ($api) {
        $api->get(
            '/',
            [
                'as' => 'xpto',
                'uses' => 'xptoController@index',
            ]
        );
        $api->group(
            [
                'namespace' => 'Abc',
                'prefix' => 'abc',
                'middleware' => ['api.auth'],
            ],
            function ($api) {
                $api->get(
                    'getAbc',
                    [
                        'as' => 'api.abc.get',
                        'uses' => 'AbcController@getAbc',
                    ]
                );
            }
        );
    }
);

Possible Solutions

https://github.com/laravel/framework/blob/5.5/src/Illuminate/Routing/RouteUrlGenerator.php version is different from previous ones. it is since 5.5 that getDomain() was introduced.

Maybe it is necessary to update the current Routing/Route.php domain() method? To something like what exists in Illuminate/Routing/Route.php:

    /**
     * Get or set the domain for the route.
     *
     * @param  string|null  $domain
     * @return $this|string|null
     */
    public function domain($domain = null)
    {
        if (is_null($domain)) {
            return $this->getDomain();
        }

        $this->action['domain'] = $domain;

        return $this;
    }
marconett commented 6 years ago

you should use 2.0.0-alpha2 for 5.6 compatibility

ldanielduarte commented 6 years ago

@marconett Hey Marco! Thank you very much for the help and sorry for the trouble.