I'm trying this for the first time and I kept going with the documentation, but I'm unable to get a correct url:
$media[0]->getUrl();
// //storage/1/19224971_101423607143177_5516819573616429777_n.jpg
$media[0]->getFullUrl();
// //storage/1/19224971_101423607143177_5516819573616429777_n.jpg
I expected something like http://example.com/storage/1/blah.jpg. Is this normal?
It does take the name of your uploaded file, except if you rename it during the process.
Wouldn't 19224971_101423607143177_5516819573616429777_n .jpg be the name of your uploaded image ?
No the problem is here //storage/. You see I don't have my domain name at the beginning. It's just two slashes.
Is see, this is not a package issue but more a Laravel workflow you should get into.
Check this to get the solution for your problem : https://laravel.com/docs/5.6/filesystem
OK, I got it. I don't think it was about Laravel file system.
For anyone else who might run into this problem, I had a trailing slash at the end of my APP_URL in my .env file:
APP_URL=http://areyoukiddingme.com/ <-- trouble
APP_URL=http://areyoukiddingme.com <-- everything fine!
Is this a bug, or am I missing something here?
I'm having the same issue, however I don't have a trailing slash in my APP_URL.
EDIT:
When changing spatie/laravel-medialibrary/src/UrlGenerator/LocalUrlGenerator R53
to return $diskUrl, I do get a valid url
@freekmurze is this a known issue?
For now I just copied the LocalUrlGenerator logic to a custom UrlGenerator with the fix I mentioned in my previous comment.
Can anyone confirm this? If it's indeed so I'm open to create a PR for this.
@jorenvh Could you by any chance share your medialibrary.php config file?
Looks like the problem is here:
LocalUrlGenerator basically removes app.url from generated link.
I think this might be a bug.
the Spatie\MediaLibrary\UrlGenerator\LocalUrlGenerator class is replacing the domain and this is making difficult to me because I'm developing to separated app with depends on each other! I think ill do the @jorenvh solution. but i think this is not a desired behavior
Edit:
I've used the getFullUrl() method and it worked like a charm, no need Custom urlGenerator
@jorenvh could you PR a failing test for us to look at?
Most helpful comment
OK, I got it. I don't think it was about Laravel file system.
For anyone else who might run into this problem, I had a trailing slash at the end of my
APP_URLin my.envfile:Is this a bug, or am I missing something here?