Lumen-framework: Target [Illuminate\Contracts\Routing\UrlGenerator] is not instantiable

Created on 7 Aug 2018  路  3Comments  路  Source: laravel/lumen-framework

  • Lumen Version: 5.3
  • PHP Version: 7.1

Description:

Having problem that occurs when Doing a Password reset . I think that problem is with this line of code:

if (! function_exists('url')) {
/**
 * Generate a url for the application.
 *
 * @param  string  $path
 * @param  mixed   $parameters
 * @param  bool    $secure
 * @return string
 */
function url($path = null, $parameters = [], $secure = null)
{
    return (new Laravel\Lumen\Routing\UrlGenerator(app()))
                            ->to($path, $parameters, $secure);
}

Steps To Reproduce:

This line of code:

$response = Password::broker($broker)->sendResetLink($request->only('email'), function (Message $message) {
        $message->subject('Your Password Reset Link');
    });

Returns:

Target [Illuminate\Contracts\Routing\UrlGenerator] is not instantiable

In AppServiceProvider i've added:

$this->app->singleton('Illuminate\Contracts\Routing\ResponseFactory', function ($app)
    {
        return new ResponseFactory($app['Illuminate\Contracts\View\Factory'], $app['Illuminate\Routing\Redirector']);
    });

Most helpful comment

Add this to your service provider:

$this->app->bind(\Illuminate\Contracts\Routing\UrlGenerator::class, function ($app) {
      return new \Laravel\Lumen\Routing\UrlGenerator($app);
});

Your UrlGenerator contract has not been bound to any instance, so you'll have to do it manually.

All 3 comments

Add this to your service provider:

$this->app->bind(\Illuminate\Contracts\Routing\UrlGenerator::class, function ($app) {
      return new \Laravel\Lumen\Routing\UrlGenerator($app);
});

Your UrlGenerator contract has not been bound to any instance, so you'll have to do it manually.

This solved the issue, thank you.

Well, it seems this is outdated and \Laravel\Lumen\Routing\UrlGenerator does not follow the \Illuminate\Contracts\Routing\UrlGenerator. It lacks setRootControllerNamespace in particular.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Andrei-Vakulski picture Andrei-Vakulski  路  3Comments

georgeboot picture georgeboot  路  4Comments

cvinothkumar picture cvinothkumar  路  3Comments

matthewsuan picture matthewsuan  路  3Comments

rtheunissen picture rtheunissen  路  3Comments