A
A
Alixx2018-03-31 16:17:30
PHP
Alixx, 2018-03-31 16:17:30

Why is storage/app/public symlink not working in Laravel?

Good afternoon. After changing the mode in xampp from cgi to mod_php, the symbolic link to storage/app/public stopped working in laravel. When I open www.mysite.local/storage , I get into the public/storage folder instead of storage/app/public. Tell me, what could be the matter? How to fix?
Contents of config\filesystem.php:

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

PS: xampp is on a laptop with windows 7. Before the mode change, the link worked ..
UPD: Or how then to display links to files? Through asset() or some other options? Or even transfer all the files to, in fact, the public / storage itself ..?
UPD 2: As a result, I found how to correct the situation correctly by getting rid of the extra route (marked by the solution).
In public , you need to delete the storage folder and re-run the artisan storage: link command - it will re-create the shortcut folder on storage\app\public. And the links began to work again without the help of the route.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alixx, 2018-04-06
@Alixx

In general, who needs the links to storage/app/public to work correctly, you can use this option, taken from here:

Route::get('storage/{filename}', function ($filename)
{
    $path = storage_path('app\public\\' . $filename);

    if (!File::exists($path)) {
        abort(404);
    }

    $file = File::get($path);
    $type = File::mimeType($path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question