ash-jc-allen / short-url

A Laravel package for creating shortened URLs for your web apps.
MIT License
1.25k stars 158 forks source link

BindingResolutionException when trying to use lib #286

Closed gfucci closed 3 months ago

gfucci commented 3 months ago

Hello!

I try use the lib but laravel return me a BindingResolutionException in Laravel 10.48.12 and php 8.3.4

Target [AshAllenDesign\ShortURL\Interfaces\UrlKeyGenerator] is not instantiable while building [AshAllenDesign\ShortURL\Classes\Builder].

I already run migrations table, add new column "cobranca_id" and add the short-url.php file in the config folder, In localhost work normally, but in prodcution throws the exception

my code

use AshAllenDesign\ShortURL\Classes\Builder as ShortUrlBuilder;
use AshAllenDesign\ShortURL\Models\ShortURL;
use Illuminate\Support\Carbon;

// continuation...

//concreate method
 private function makeShortUrl(Cobranca $cobranca): string
    {
        $cobrancaId = $cobranca->id;

        $shortUrl = app(ShortUrlBuilder::class)
            ->beforeCreate(function (ShortURL $model) use ($cobrancaId): void {
                $model->cobranca_id = $cobrancaId;
            })
            ->deactivateAt(\Carbon\Carbon::now()->addDays(50))
            ->destinationUrl($cobranca->link_pagamento)
            ->make();

        return $shortUrl->default_short_url;
    }

what am I doing wrong?

ash-jc-allen commented 3 months ago

Hey! It's interesting that this is working locally but not in production. That makes me think it might have something to do with your config being cached in production.

Does it solve your problem when you flush your cached config and rebuild it? It might be worth running this:

php artisan config:cache

Hopefully this fixes the issue? 🙂

gfucci commented 3 months ago

Hey! It's interesting that this is working locally but not in production. That makes me think it might have something to do with your config being cached in production.

Does it solve your problem when you flush your cached config and rebuild it? It might be worth running this:

php artisan config:cache

Hopefully this fixes the issue? 🙂

I updated the vendor, ran config:cache and config:clear but it's still the same, do I need to register the provider manually in production?

ash-jc-allen commented 3 months ago

Assuming you haven't disabled provider auto-discovery, the package's provider should be automatically registered. Please could you give me the following details to help me investigate:

If you could recreate a fresh Laravel project that has the error, that'd be great and save a lot of time! 😄

gfucci commented 3 months ago

Assuming you haven't disabled provider auto-discovery, the package's provider should be automatically registered. Please could you give me the following details to help me investigate:

* The Short URL version you're using

* What's inside your `config/short-url.php` file

* What happens when you call `config('short-url')`?

If you could recreate a fresh Laravel project that has the error, that'd be great and save a lot of time! 😄

I fixed the error, I registered the provider manually in my app.php in the providers array, when I published the provider locally and saved the short-url.php with composer update on the server I thought it was enough to work, thanks for the help.