简体   繁体   中英

Edit Input File Laravel 5.1

i want edit a input file but when i edit the form i can't update the information about the picture (the path of picture for database) I have the next code in the partial new (the partial be in path comp.new.form ):

<div class="input-field col s12">
  {!!Form::text('titulo',null,['class'=>'validate', 'length'=>'25'])!!}
  {!!Form::label('titulo','Titulo')!!}
</div>
<div class="input-field col s12">
  <div class="file-field input-field">
      <input class=" file-path validate" type="text"/>
       <div class="btn blue darken-4">
          <span>Noticia</span>
          {!!Form::file('noticia',['class'=>'blue darken-4'])!!}
       </div>
  </div>
</div>
<div class="input-field col s12">
  {!!Form::text('descripcion',null,['class'=>'validate', 'length'=>'25'])!!}
  {!!Form::label('descripcion','Descripcion')!!}
</div>

I Have a view for Create:

{!!Form::open(['route'=>'noticia.store', 'method'=>'POST'])!!}
    @include('comp.new.form.new')
    {!!Form::submit('Publicar',['class'=>'btn blue darken-4'])!!}
{!!Form::close()!!}

And the view for Edit:

{!!Form::model($new,['route'=>['noticia.update',$new->id], 'method' => 'PUT'])!!}       
      @include('comp.new.form.new')
     {!!Form::submit('Actualizar',['class'=>'btn blue darken-4'])!!}
{!!Form::close()!!} 

Into the model Report have the next code:

class Report extends Model
{
  use SoftDeletes;
  protected $table = 'reports';

  protected $fillable =  ['titulo','descripcion','noticia','institution_id'];
  protected $dates = ['deleted_at'];

  public function setNoticiaAttribute($value)
  {
     if( ! empty($value))
     {
         $this->attribute['noticia'] = $value;
     }
  }

} 

But when I try to update nothing happens, even eliminating the method setNoticiaAttribute, always keeps the path to that achievement select another file update , that is correct ?. Thanks

You have to include in your form attributes the enctype = multipart/form-data to pass the file information

{!!Form::open(['route'=>'noticia.store', 'method'=>'POST', 'enctype' => 'multipart/form-data'])!!}
   @include('comp.new.form.new')
   {!!Form::submit('Publicar',['class'=>'btn blue darken-4'])!!} 
{!!Form::close()!!}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM