Laravel 5/Voyager部署XAMPP后图片显示异常求助
Let’s break down what’s causing this image issue and fix it step by step—since php artisan serve works fine (it uses Laravel’s built-in server which handles paths differently), the problem is tied to how XAMPP’s document root structure interacts with your Laravel storage setup.
1. Fix the Storage Symbolic Link
The core issue is almost certainly a misaligned storage symlink. Your XAMPP directory structure has the public web folder separated from the Laravel core, so the default symlink created by php artisan storage:link won’t work here.
Your current structure:
xampp/ ├── htdocs/ (web root) │ ├── MyProject/ # Your public-facing directory │ ├── storage/ # Likely a misplaced symlink/folder ├── MyprojectCore/ │ ├── public/ │ ├── storage/ # Laravel's actual storage directory
You need to create a symlink that connects htdocs/MyProject/storage directly to MyprojectCore/storage/app/public:
- Windows (run Command Prompt as Administrator):
mklink /D "C:\xampp\htdocs\MyProject\storage" "C:\xampp\MyprojectCore\storage\app\public" - macOS/Linux:
ln -s /Applications/XAMPP/htdocs/MyprojectCore/storage/app/public /Applications/XAMPP/htdocs/MyProject/storage
Note: Delete the existing htdocs/storage folder first if it’s not a symlink.
2. Correct Paths in index.php
I spotted a possible typo in your index.php—you’re referencing ECRCore but your core directory is named MyprojectCore. Update these lines to match your actual folder structure:
// Before require __DIR__.'/../../ECRCore/vendor/autoload.php'; $app = require_once __DIR__.'/../../ECRCore/bootstrap/app.php'; // After require __DIR__.'/../../MyprojectCore/vendor/autoload.php'; $app = require_once __DIR__.'/../../MyprojectCore/bootstrap/app.php';
3. Verify Configurations
Double-check these settings to ensure they align with your XAMPP setup:
config/filesystem.php
Your public disk config looks correct, but confirm it points to Laravel’s actual storage:
'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), // Resolves to MyprojectCore/storage/app/public 'url' => env('APP_URL').'/storage', 'visibility' => 'public', ],
.env
Keep your APP_URL clean (no trailing slash is preferred):
APP_URL=http://localhost:8080/MyProject
config/voyager.php
Your Voyager config is already set to use the public disk, which is correct:
'storage' => [ 'disk' => 'public', ],
4. Clear Laravel Caches
After making these changes, clear your config and route caches to ensure Laravel picks up the new settings:
cd /path/to/MyprojectCore php artisan config:cache php artisan route:cache
Test the Fix
Upload a new image through your app, then check if it displays. If it still breaks, inspect the image’s src attribute in your browser—it should point to something like http://localhost:8080/MyProject/storage/your-image.jpg. If you can’t access that URL directly, the symlink or path is still misconfigured.
内容的提问来源于stack exchange,提问作者Led

