I have an attachOne relation set to save files as private folder like this:
public $attachOne = [
'certificateFile' => [\System\Models\File::class, 'public' => false]
];
But all files end up in /storage/app/uploads/public folder.
When querying such attachment, getLocalPath() points to /storage/app/uploads/private where the file cannot be found.
This worked in OC1 but not in OC3.
Has anyone addressed this?
Hey @jan-vince
Check the documentation on this, it includes a mention about the public flag if you prepare the file manually.
Hi @daftspunk and thank you - this works but I had to change the order as fromFile method already needs to know is_public setting like this:
$file = new File;
$file->is_public = false;
$file->fromFile($fileName);
$file->save();
1 Like
PS: Just a note @daftspunk - I have set 'public' => false on my model’s attachOne relation.
And now I use $file->is_public = false in my code preparing file to be attached to my model.
But when I change the model’s relation setting to 'public' => true sometime in the future, I will have to find all places in my code and change $file->is_public = false.
I would say this is not the best practise.
What do you think? What is the best approach here?