I am using v7 of this library, when I use the method:
echo $inmueble->getFirstMediaUrl('destacadas');
I got this: //storage/1/1-1.jpg
But a colleague is working on the same project also and the method shows him the full path:
http://localhost:8888/inmuebles/public//storage/1/1-1.jpg
Do I need to change my configuration or why I am not able to get the full path automatically?
How about if you try $inmueble[0]->getFullUrl()?
I didn't find the getFullUrl()method on docs, also $inmueble it's already the model which it's related to the media library, not an array. Thanks for your suggestion!
Laravel uses the app.url config value to generate urls. You probably need to specify APP_URL in your .env file.
APP_URL is already specified but by some reason it's not been attached to the img path, what else could it be?
When you Tinker/dump config('app.url'), what's the result?
When I do: dd(config('app.url'));
I got this: "http://inmuebles.test/" (what I defined in .env)
This might be related to the way your storage is configured, but you'd need to dive into the LocalUrlGenerator class to find out what's missing.
Did you try fullUrl as previously suggested? It's a public method on Media, I'd suggest doing that if you need a full path.
https://github.com/spatie/laravel-medialibrary/blob/v7/src/Models/Media.php#L45-L51
I tried $inmueble->getFirstMedia('destacadas')->getFullUrl();
but I still got the same incomplete path:
//storage/1/1-1.jpg
hi @eichgi,
Not sure what's going on here. You'll need to add some debug statements to see where it's going wrong.
Here's a good place to get started, it's where we retrieve the disk's base url: https://github.com/spatie/laravel-medialibrary/blob/7e457f86b98943680dcea8ccb4a6e24c1de54739/src/UrlGenerator/LocalUrlGenerator.php#L49
Sorry, I was kind off. Last day I changed the disk I was using (media) for public and everything went ok again. I guess I haven't tried but thanks for the help 馃憤
@eichgi I'm having the same problem, can you tell me how you solved yours?
Hi mokhosh, as I mentioned I was using another disk for storing files, which I called media. It wasnt working so I changed it back to public disk on medialibrary config and it works like a charm again. I hope it works for you too
Well, I haven't even published the config. I'm just using the defaults. So that shouldn't be my problem, right?
I think public is the default option disi, but publish them to ensure it is.
In case someone has the same error in my case was the URL defined in the env file:
You should put the URL without the final slash:
Bad: APP_URL=http://my-domain.test/
Good: APP_URL=http://my-domain.test
In case someone has the same error in my case was the URL defined in the env file:
You should put the URL without the final slash:
Bad:APP_URL=http://my-domain.test/
Good:APP_URL=http://my-domain.test
I was having the same issue as @eichgi and @alfonsobries reply fixed it for me.
The problem may be solved,
before you can use storage in public folder change APP_URL in .env and config/App.php
http://localhost change to
http://localhost/project/public
and run this may be ok.
The problem may be solved,
before you can use storage in public folder change APP_URL in .env and config/App.php
http://localhost change to
http://localhost/project/public
and run this may be ok.
I could reproduce that problem on windows - sadly none of the solutions discussed here work.
Same here - any solution? Running pretty close to a fresh install of Laravel
@ingageco My install was a fresh one. Did you try cleaning all the caches?
i noticed that when APP_URL contains https getFirstMediaUrl return correctly full url but with there is a problem with http. Only partial url is being returned
Enter these commands php artisan config:clear to clear your configuration and php artisan cache:clear to clear your cache
Then var dump your APP_URL by typing this code dd(config('app.url')) .
Remember to enter the above commands every time you make changes to your .env file.
In case someone has the same error in my case was the URL defined in the env file:
You should put the URL without the final slash:
Bad:APP_URL=http://my-domain.test/
Good:APP_URL=http://my-domain.test
Thank you this was help me in my case
Most helpful comment
In case someone has the same error in my case was the URL defined in the env file:
You should put the URL without the final slash:
Bad:
APP_URL=http://my-domain.test/Good:
APP_URL=http://my-domain.test