Using images in Laravel

0

You see, I have a table of plants:

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();
        });

Among the variables of the plant is a photo and I want the image to be able to be imported into my form. For this, I have this form:

<form method="POST" action="../planta"> {{ csrf_field() }}
        <div class="form-group">
            <label for="nombre" class="col-md-12 control-label" enctype="multipart/form-data"> {{ __("Nombre") }}
            </label>
            <input id="nombre" class="form-control" name="nombre" value="{{ old('nombre') }}"/>
        </div>

        <div class="form-group">
            <label for="tamaño" class="col-md-12 control-label"> {{ __("Tamaño") }}
            </label>
            <input id="tamaño" class="form-control" name="tamaño" value="{{ old('tamaño') }}"/>
        </div>

        <div class="form-group">
            <label for="flor" class="col-md-12 control-label"> {{ __("Flor") }}
            </label>
            <input id="flor" class="form-control" name="flor" value="{{ old('flor') }}"/>
        </div>

        <div class="form-group">
            <label for="hoja" class="col-md-12 control-label"> {{ __("Hoja") }}
            </label>
            <input id="hoja" class="form-control" name="hoja" value="{{ old('hoja') }}"/>
        </div>

        <div class="form-group">
            <label for="descripcion" class="col-md-12 control-label"> {{ __("Descripción") }}
            </label>
            <input id="descripcion" class="form-control" name="descripcion" value="{{ old('descripcion') }}"/>
        </div>

        <label class="btn btn-warning" for="foto">
            <input id="foto" name="foto" type="foto" style="display:none;"> {{ __("Subir imagen (Opcional)") }}
        </label>

        <button type="submit" name="addPlanta" class="btn btn-default"> {{ __("Añadir Planta") }}
        </button>
    </form>

And here is the result. Among the things that you will see is an icon that is for the photo. The problem is that this button does not do anything. It seems that I would have to put it in php artisan serve mode, but the truth is that this mode is unpleasant and it does not let me log in, when I do not have any problems in a normal way .

Does anyone know a way out of this, please?

    
asked by Miguel Alparez 13.02.2018 в 22:18
source

1 answer

1

To be able to load images with the form, the attribute: enctype="multipart / form-data" you have to put it inside the form tag's opening form:

<form method="POST" action="../planta" enctype="multipart/form-data">
    
answered by 13.02.2018 / 23:15
source