i have a table which has the fields attachment_id
and file_path
,file_path field stores the path from s3 bucket corresponding to the attachment id .
is there any way to initialize a method or call an event directly from the model to delete file from s3 when the data in file_path
field is updated or deleted ?
2
Answers
Just create a method or helper inside or outside of that model which delete the file from S3 Bucket, then setup an observer to trigger it during updated or deleting
e.i.
On your model
Then generate an Observer
then you can call that method on
updated
anddeleting
eventMake sure to check out Observer docs
You can use
$dispatchesEvents
.Create an event and then, in your model:
Check this out for more information: https://laravel.com/docs/9.x/eloquent#events