简体   繁体   English

编辑输入文件Laravel 5.1

[英]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 ): 我想编辑一个输入文件,但是当我编辑表单时,我无法更新有关图片的信息(数据库图片的路径),我在部分新代码中有下一个代码(部分在路径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 ?. 但是,当我尝试更新时,什么也没有发生,即使消除了setNoticiaAttribute方法,也始终保持该成就的路径选择另一个文件更新,对吗? Thanks 谢谢

You have to include in your form attributes the enctype = multipart/form-data to pass the file information 您必须在表单属性中包含enctype = multipart / form-data才能传递文件信息

{!!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()!!}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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