How to save image and several fields in the Laravel 5.2 database?

0

Good morning I want to save the brand, image and status in the database; I'm using

  

link

When I click on save I get the following error, which can be the problem? Thanks for your input.

This is my Route

Route::resource('marca','Controladores\marca');

driver:

public function store(Request $request)
{
    $photo = $request->file('image');
    $filename = time() . '.' . $photo->getClientOriginalExtension();
    Image::make($photo)->resize(350,350)->save(public_path('images/marca/' . $filename));
    $imagen->image = $filename;
    $imagen->save();
    return view('Marca.crear');
}

View:

    {!!Form::open(['route'=>'marca.store', 'method'=>'POST', 'files'=>true])!!}
    <div class="form-group form-float">
        <div class="form-line">
           {!!Form::text('nombre',null,['id'=>'nombre','class'=>'form-control'])!!}
           {!!Form::label('name','Marca', array('class' => 'form-label'))!!}
        </div>
    </div>

    {!!Form::label('Imagen')!!}
    {!!Form::file('image', null, array('id' => 'imagen'))!!}
    <br>

    {!!Form::label('Estado')!!}
     <div class="switch">
        <label>INACTIVO
        {!!Form::checkbox('checkbox','value','true')!!}
        <span class="lever">    
        </span>ACTIVO</label>
    </div>
    <br>
    <!-- <button class="btn btn-primary waves-effect" type="submit">REGISTRAR</button> -->
    {!!Form::submit('REGISTRAR',['name'=>'registrar', 'id'=>'registrar', 'class'=>'btn btn-primary waves-effect'])!!}
{!!Form::close()!!}
    
asked by Devin Stiven Zapata Areiza 04.01.2018 в 14:42
source

1 answer

1

According to the code of your controller, you did not instantiate the variable $imagen , import your model and instantiate the object.

$imagen = new Imagen();
$imagen->filename = $filename;
$imagen->save();

Good luck!

    
answered by 05.01.2018 в 01:16