I'm working with a project that is using Laravel (api) and Angular 5 (front-end) on GoDaddy. In order to use Laravel safely on GoDaddy, I had to put all the Laravel files one directory back from public_html
and all the Angular files in public_html
. In order for this to work properly, I had to move the Laravel public folder to public_html
and point to the Laravel file's via an absolute path. Everything is working so I know I'm headed in the right direction.
Laravel path - /home/website/laravel/
Public path - /home/website/public_html/
The only problem I'm having is trying to serve-up images for an image gallery. I store all the images in Laravel's storage
directory and save the image path's in the db. When it's time to load all the images via Angular, I call the api and it returns all the image name's in a collection and Angular appends the path. Here's an example - https://website.com/storage/media/events/1/m_22721a76-8f0a-4ce2-97a5-e5ac169127a5.jpg
.
Since my images are kept one directory back from public_html
, they cannot be reached and are broke. My first thought is to save all the images in a directory in public_html
, but I'm not sure if I can change Laravel's filesystems
config to allow that. I also thought about trying to use .htaccess
to detect a certain path and redirect, but I couldn't get it to work. I feel like using Laravel's filesystems
is the way to go, but couldn't get it to work, here is what I came up with:
filesystems.php
'public' => [
'driver' => 'production',
'root' => storage_path('/home/website/public_html/storage/media/'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
ImageGalleryController.php
if(App::environment('local'))
{
Storage::disk('local')->put('events' . '/' . $id . '/t_' . $path, (string) $thumb->encode());
}
else if(App::environment('test'))
{
Storage::disk('test')->put('events' . '/' . $id . '/t_' . $path, (string) $thumb->encode());
}
else {
Storage::disk('production')->put('events' . '/' . $id . '/t_' . $path, (string) $thumb->encode());
}
With my current file setup, any ideas how I can display images from Laravel's storage directory?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2HSgHeX
via IFTTT
Aucun commentaire:
Enregistrer un commentaire