I have written the following code in laravel.
if ($request->hasFile('foto')) {
$file = $request->file('foto');
$nama = 'foto-' . date('YmdHis') . '.' . $file->getClientOriginalExtension();
Storage::disk('public')->put('img/' . $nama, file_get_contents($file));
$user->foto = "storage/img/$nama";
}
this code works in local but when going up to production the file cannot be displayed . the filesystem config
<?php
return [
'default' => env('FILESYSTEM_DISK', 'local'),
'disks' => [
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
];
I tried this code
Route::get('/symbolic_link', function(){
$targetFolder = storage_path('app/public');
$linkFolder = $_SERVER['DOCUMENT_ROOT'] . '/storage';
symlink($targetFolder, $linkFolder);
});
but it's still an error