You see, I'm doing a url with which to see images of a table of plants. web.php:
Route::get('/images/{path}/{attachment}', function($path, $attachment){
$storagePath = Storage::disk($path)->getDriver()->getAdapter()->getPathPrefix();
$imageFilePath = $storagePath . $attachment;
if(File::exists($imageFilePath)){
return Image::make($imageFilePath)->response();
}
});
The function in plantas.php:
public function rutas(){
return "images/fotos/" . $this->foto;
}
And the code in filesystems.php:
'planta' => [
'driver' => 'local',
'root' => storage_path('app/fotos'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
After this, I have in \storage\app\fotos
an image called cactus.jpg
, so after activating php artisan serve
, I write http://127.0.0.1:8000/images/fotos/cactus.jpg
What will be failing?
Edit: I have tried to make the code $storagePath
before dd("Hola")
That works, but if it is before $imageFilePath
, the error message is skipped again. In other words, the error is in the code $storagePath = Storage::disk($path)->getDriver()->getAdapter()->getPathPrefix();
More things: I'm going to include the contents of the .env file:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:W3VBG3wxQtSobMUgXfRC5B1+A5hKAQqqp67ll1DiQe0=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=plantas
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1