By rock oo
At my Digital Ocean basic application, I used CRUD photo folder under public directory at laravel. But when I deploy the application from GitHub repo, it remove all photos and make same with my GitHub repo. Is there anyway to exclude the custom folders under public directory of laravel?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hi there @rockoo,
This happens as the DigitalOcean App platform is based on Kubernetes, meaning that each deployment is a separate immutable container.
So after each redeployment, all changes to the container will be lost.
To sort this out, you need to use an Object Storage, like the DigitalOcean Spaces.
To do so, you can follow the instructions from step 5 of this tutorial here:
Basically, what you need to do is:
s3
driver:composer require league/flysystem-aws-s3-v3
.env
file:DO_SPACES_KEY=EXAMPLE7UQOTHDTF3GK4
DO_SPACES_SECRET=exampleb8e1ec97b97bff326955375c5
DO_SPACES_ENDPOINT=https://ams3.digitaloceanspaces.com
DO_SPACES_REGION=ams3
DO_SPACES_BUCKET=sammy-travellist
config/filesystems.php
you need to define the details for your S3 bucket as follows:'spaces' => [
'driver' => 's3',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'region' => env('DO_SPACES_REGION'),
'bucket' => env('DO_SPACES_BUCKET'),
],
Still, in the same file, locate the cloud entry and change it to set the new spaces disk as the default cloud filesystem disk:
'cloud' => env('FILESYSTEM_CLOUD', 'spaces'),
<?php
use Illuminate\Support\Facades\Storage;
public function uploadPhoto(Request $request)
{
$photo->image = $request->image->store('/', 'spaces');
Storage::setVisibility($photo->image, 'public');
$photo->save();
return redirect()->route('home');
}
<img src="{{ asset('storage') . '/' . $photo->image }}" />
Once you implement the S3 driver or the DigitalOcean Space, you will have persistent storage, so when your users upload images via your app, the images will not be uploaded to the container inside the DigitalOcean App itself, but the S3 bucket, so once the container gets redeployed your images will stay intact on the object storage.
Hope that this helps. Let me know how it goes. Best, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.