Download private files
I'm trying to create a scenario where only logged in users can see uploaded files, I've seen it asked here a few times but I can't make sense of the answers.
I have this
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('client_id')
->relationship(name: 'client', titleAttribute: 'client_name'),
Forms\Components\TextInput::make('project_name')
->required()
->maxLength(100),
Forms\Components\FileUpload::make('shape_file')
->preserveFilenames()
// directory is record id of the project
->directory(fn ($record) => 'project-shapes/' . $record->id)
->previewable(false)
->downloadable()
->disk('private')
]);
}
and this in the filesystem config
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'url' => env('APP_URL').'/storage',
'visibility' => 'private',
'throw' => false,
],
I have public sym linked.
Everything works including event listeners for deleting but I can't download the file from the form.
I would also like to have an icon link in the resource table to the file.
Thanks Dan1 Reply
Solution
I resolved this by adding a route to my private file paths in web.php
And then my controller