编辑输入文件Laravel 5.1

时间:2015-07-14 04:24:53

标签: php laravel-5.1 materialize

我想编辑输入文件,但是当我编辑表单时,我无法更新有关图片的信息(数据库的图片路径) 我有部分新的下一个代码(部分在路径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>

我有创建视图:

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

编辑视图:

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

进入模型报告有下一个代码:

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

} 

但是当我尝试更新没有任何反应时,即使取消了setNoticiaAttribute方法,也始终保持该成就的路径选择另一个文件更新,这是正确的吗?感谢

1 个答案:

答案 0 :(得分:0)

您必须在表单属性中包含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()!!}