I am currently facing difficulties in displaying a file from storage on Laravel 6

I currently have a Laravel 6.0 application that allows users to upload files to a server and saves them in the storage file system of laravel. This set up has been functioning smoothly in an older Laravel 5.6 project.

The link provided by the Controller looks like this:

domainame.com/public/file?folder=foldername&file=1569323440filename.png

Controller Logic

public function getFile($foldername, $filename)
{
    $fullpath = "app/{$foldername}/{$filename}";

    return response()->download(storage_path($fullpath), null, [], null);
}

public function getFilesubfolder($foldername, $subfolder, $filename)
{
    $fullpath = "app/{$foldername}/{$subfolder}/{$filename}";

    return response()->download(storage_path($fullpath), null, [], null);
}

View Section

{{ route('file.show' ,['folder' => 'empresas' , 'file' => $factura->archivo])}}

However, I am encountering a 404 error because the link being accessed does not exist. In my previous project, the link structure was different:

domainame.com/public/folder/file

To troubleshoot, I created a symlink to the storage system. Is there another configuration or setup step that I might be missing?

Answer №1

After tackling my issue, I've decided to share the solution in case someone stumbles upon it through a Google search or any other means:

The mistake I made was related to Laravel 6.0's requirement for variables in routes to be literal.

In my particular scenario, I made the following adjustment:

{{ route('file.show' ,['foldername' => 'empresas' , 'filename' => $factura->archivo])}}

This change proved crucial in resolving the error that had been eluding me. Hopefully, this information proves useful to others facing a similar situation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm encountering an error that I wasn't expecting - a T_FUNCTION error

Having a frustrating issue where I am encountering the following error message: Parse error: syntax error, unexpected 'function' (T_FUNCTION) in C:\xampp\htdocs\chat\inc\chat.func.php on line 6 I have been unable to ...

The mbstring extension is required but not found in your PHPMyAdmin setup

Upon the successful installation of phpmyadmin and running it on localhost/phpmyadmin, an error message popped up: phpMyAdmin - Error The mbstring extension is missing. Please check your PHP configuration However, upon checking the console with php -m ...

Utilizing Laravel's Array and JSON casting feature for seamless integration with Algolia

I am encountering an issue while attempting to send data to Algolia using the toSearchableArray method. The strings from my database are transferring correctly, but I'm facing a challenge with nested JSON data—it's being sent as an escaped stri ...

Combining PHP and MySQL with a join statement to organize various values as a row within the mysql_fetch array

Currently, I am utilizing a MySQL INNER JOIN statement that produces multiple results for a single distinct record in the main table due to the joins, much like the scenario discussed in How to Join Multiple Joins yet return Distinct Values The query I hav ...

Using ReactJs Component to interact with Laravel Api and retrieve uploaded images

I need assistance retrieving my list from the Laravel API. I have successfully fetched the list details, but I am encountering difficulties fetching details with images. My card.js component import React, {useState, useEffect} from 'react'; imp ...

I am curious to see the number of people who have made their selection

I am currently using JavaScript to alter the text value from "select" to "selected". My next step is to include the selected text in a cart. Can you please provide some guidance? Thank you in advance. PHP CODE : <a class='btn slct' href=&ap ...

Matching query string patterns using regular expressions

My code generates a query string and iterates through it to validate the query strings. $pi = An ip address defined $bo = The content of a file. I am searching within the $bo, trying to find matches with $pi. I aim to display ALL lines that match this st ...

Preventing the override of product description fields in a specific language through a webservice

My goal is to synchronize product data between two Prestashop websites using a webservice. Specifically, I want the description of a product on the destination website to match the description of the same product on the source website after synchronization ...

Utilizing PHP to save array values in distinct columns within a table

Below is the code snippet I have been working on: $month = array('red','green','red'); $values = array(); foreach($month as $dataset) { $values[] = ($dataset); } $columns = implode(", ",array_keys($values)); $escaped_valu ...

Combining PHP tables using the similar_text function for updating purposes

I have two MySQL tables that I need to combine: table_1 -------------------------------------------------------- id | table_1_name | table_1_art -------------------------------------------------------- 1 | Ernest Hemingway | ...

What is the best way to automatically insert data into a database at regular intervals, while ensuring that users are unable to manipulate the timing through inspect

Is there a secure way to insert 1 point into the database every x seconds without allowing users to manipulate the interval time through inspect element? var time = 1; var interval = setInterval(function() { if (time != time + 1) { ...

Retrieve data entries from a database that have been added in the past day

I'm on a quest to figure out how I can retrieve data from the database that has been submitted within the past 24 hours. Within the table named topics, there is a column defined as start_date which utilizes timestamps. How would I go about querying t ...

Sorting and breaking a while loop based on a variable in PHP

I'm facing an issue that has been puzzling me for the past two days. As a newbie in php, I am struggling to understand why my while loop is returning multiple select fields for each option within a select field. For example, when I have a "choose colo ...

Exploring the utilization of doctrine within Symfony2

Currently, I am tackling a php project and encountering an issue with the database. The following code snippet is what I am using to extract data from the database: public function getSeenAction(Request $request , $notificationId) { $sessionId = $requ ...

Inserting information into a SQL database using PHP

Looking for some assistance here. I've double-checked the SQL table names multiple times, but whenever I try to post, I keep getting an error. I'm fairly new to this, so any help would be greatly appreciated. Thanks in advance. require_once(&ap ...

issues with opencart email functionality

My OPENCART website suddenly stopped sending out emails. It seems like the mail server settings from Godaddy might have changed as none of the SSL/Mail settings are working for me. I'm not receiving any emails for registrations, lost passwords, or eve ...

Transforming JSON MySQL data into a visually appealing D3 plot

I am struggling to visualize my mysql data using d3. I have attempted to convert it into JSON format using PHP, but so far, it hasn't been successful! To test the functionality, I followed the instructions outlined here. I tried using simple-graph.ht ...

"Receiving an 'undefined index' error when attempting to post in Ajax with

Need help with sending data from client to server using AJAX in PHP. I am facing an issue when trying the following code: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script type="text/javascrip ...

I'm looking to redirect a 404 page in my PHP code - where is the best place to do so?

I found the correct code for redirecting 404 errors when a page is not found during redirection. However, I am unsure of where to implement this code in my PHP file. Should I place it within a specific tag on my home page? When I tried placing it at the ...

Transforming identification to forward slash in .htaccess

Could you assist me in rewriting the URL id from www.website.com/script/?id=3 to www.website.com/script/3/? This essentially means removing the "?id=" part. Below is the code in my .htaccess file: RewriteEngine on RewriteRule ^script/([^/\.]+)/?$ s ...