iqlas's avatar
Level 4

Access the files uploaded to storage\app\subfolder\filename.ext

I am trying to store uploaded files to storage\app folder with subfolder created for each upload. Below is the code for uploading files.

$client=Client::find($client_id);
        if($request->hasFile('attachment')){
            $attachment=$request->attachment;
            $path = $attachment->storeAs("clients/".$client->code, \Carbon\Carbon::now()->timestamp.'.'.$attachment->extension());
        }else{
            $path='';
        }

Upload is successful, and the file is getting stored in storage\app\clients\client_code\filename.ext. I am trying to access the uploaded file by

<a href="{{ Storage::url($cr->attachment) }}"><i class="fa fa-download"></i></a>

When i click on link, it throws 404 Error.

Can someone let me know how to access the uploaded files.

0 likes
1 reply
AhimbisibweRoland's avatar
Level 9

One create the symbolic link between the public directory and the storage path

php artisan storage:link

Then to access the files use the asset helper by prepending the storage word

<a href="{{asset("storage/$cr->attachment") }}"><i class="fa fa-download"></i></a>

and that shoud fix it

Please or to participate in this conversation.