簡體   English   中英

編輯輸入文件Laravel 5.1

[英]Edit Input File Laravel 5.1

我想編輯一個輸入文件,但是當我編輯表單時,我無法更新有關圖片的信息(數據庫圖片的路徑),我在部分新代碼中有下一個代碼(部分在路徑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方法,也始終保持該成就的路徑選擇另一個文件更新,對嗎? 謝謝

您必須在表單屬性中包含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