The difference in storage paths between your local setup and production server is likely due to differences in the server configurations.
To deal with this situation, you can create a configuration file that sets the storage path based on the environment. For example, you can create a file called filesystems.php in the config directory with the following contents:
<?php
return [
'default' => env('FILESYSTEM_DRIVER', 'local'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'blog' => [
'driver' => 'local',
'root' => env('BLOG_STORAGE_PATH', storage_path('app/blog')),
'url' => env('APP_URL').'/blog',
'visibility' => 'public',
],
// ...
],
];
In this file, you can define a disk called blog with a root path that is either the default storage_path('app/blog') or a custom path specified by the BLOG_STORAGE_PATH environment variable.
Then, in your .env file, you can set the BLOG_STORAGE_PATH variable to /blog/images on your local setup and /storage/blog/images on your production server.
# .env
BLOG_STORAGE_PATH=/blog/images
# .env.production
BLOG_STORAGE_PATH=/storage/blog/images
Finally, in your code, you can use the Storage facade to access the blog disk and store or retrieve files from the appropriate path:
use Illuminate\Support\Facades\Storage;
// Store a file
Storage::disk('blog')->put('xyz.jpg', $fileContents);
// Retrieve a file
$url = Storage::disk('blog')->url('xyz.jpg');