You see, I have a table of plants which has the following properties:
Schema::create('plantas', function (Blueprint $table){
$table->increments('id');
$table->string('nombre'); // Nombre de la planta.
$table->string('tamaño'); // Clasifica segun si es arbol, arbusto o hierba.
$table->string('flor'); // Si tiene o no flor.
$table->string('hoja'); // Si es de hoja caduca o perenne.
$table->text('descripcion'); // Caracteristicas del vegetal.
$table->string('foto')->nullable(); // Esta variable sera utilizada para almacenar fotos. Es opcional.
$table->timestamps();
});
I have to create a view in which the characteristics of each plant are shown, including a photo of the plant (if it has one). Here I show the view:
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div align="center" class="panel panel-default">
<div class="panel-heading">
<h1 class="text-center text-mute"> {{ __("Plantas") }} </h1>
</div>
<div class="panel-body">
@Logged()
<a href="formulario/plantas">Crear una nueva planta</a>
@include('partials.errors')
@else
<p style="color:#0000FF">Para poner insertar nuevas plantas tienes que iniciar sesión</p>
@endLogged
</div>
</div>
@forelse($planta as $plantas)
<div class="panel panel-default">
<div class="panel-heading">
<h3><a href="comentarios/{{ $plantas->id }}">{{ $plantas->nombre }}</a></h3>
</div>
<div class="panel-body">
<h4>{{ $plantas->descripcion }}</h4>
@if($plantas->attachment)
<img src="{{ $plantas->pathAttachment() }}" class="img-responsive img-rounded" />
@endif
</div>
<div class="panel-body">
<b>Tamaño:</b> {{ $plantas->tamaño }}<br>
<b>Flor:</b> {{ $plantas->flor }}<br>
<b>Hoja:</b> {{ $plantas->hoja }}<br>
<span class="pull-right"> {{ __("Comentarios") }}: {{ $plantas->comentarios->count() }} </span>
</div>
</div>
@empty
<div class="alert alert-danger">
{{ __("No hay ninguna planta en este momento") }}
</div>
@endforelse
@if($planta->count())
{{$planta->links()}}
@endif
</div>
</div>
</div>
</div>
@endsection
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();
}
});
plantas.php:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class plantas extends Model{
protected $table = 'plantas';
protected $fillable = [
'nombre', 'tamaño', 'flor', 'hoja', 'descripcion', 'foto',
];
public function comentarios(){
return $this->hasMany(Comentario::class,'planta');
}
public function pathAttachment(){
return "/images/planta/" . $this->attachment;
}
}
However, I still can not see the images.
What will I be leaving?
Edit: Here you have filesystems.php.
<?php
return [
'default' => env('FILESYSTEM_DRIVER', 'local'),
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'planta' => [
'driver' => 'local',
'root' => storage_path('app/planta'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
];
More things: Once I upload the image with my form, when I look at the route in phpMyAdmin I see that the following route appears: * C: \ xampp \ tmp * However, I go to the indicated route and the images do not appear. Will it have to do with my problems?
Also another detail. I've tried putting the following in the view:
{{$ plants-> pathAttachment ()}}
CASI manages to put the path where I currently keep the image, but at the end there it stayed.