I was asked to create several websites for a non-profit organization, but using a single database and a single administration area.
I managed to create the admin area and two websites, but I’m having trouble displaying images on the websites.
I have three URLs, which are as follows (I’m on a local environment):
www.admin.test
www.website1.test
www.website2.test
etc…
The store method of my controller is simple but functional:
$request->validate([
'title' => 'required',
'content' => 'required',
'website_id' => 'required',
]);
$filename = time() . '.' . $request->post_image->extension();
$path = $request->file('post_image')->storeAs(
'posts_featured_images',
$filename,
'public'
);
$post = Post::create([
'title' => $request->title,
'slug' => $slugify->slugify($request->title),
'website_id' => $request->website_id,
'user_id' => Auth::user()->id,
'content' => $request->content
]);
$image = new PostImage();
$image->path = $path;
$image->post_id = $post->id;
$post->post_image()->save($image);
I have no problem viewing the image in my administration area (www.admin.test) in the edit view or show with this:
<img src="{{ Storage::url($post->post_image->path) }}" class="img-fluid" width="50%">
However, I don’t know how to display this image on www.website1.test, for example.
In my env file, I added this line: ADMIN_URL=http://admin.test to retrieve it in my views, but it doesn’t work.
I tried this, for example, but it doesn’t work.
<img src="{{ Storage::url(env('ADMIN_URL')) }}/{{ $post->post_image->path }}" alt="Image">
So my question is: is it possible to display my images on all my websites, and if so, how?
Thank you all in advance!