2017-03-23 16 views
0

私は、複数のファイルをアップロードしたLaravel 5.2のWebサイトを持っています。私は機能していないファイルの削除ボタンがあります。ユーザーは単にページにリダイレクトされますが、ファイルはまだそこにあります。laravel 5.2ファイルを削除するボタン

show.blade

<div class="row"> 
            <form class="col-xs-2" method="POST" action="/exception/{{$truckingDelivery->exception->id}}"> 

             {!! csrf_field() !!} 

             <input type="hidden" name="_method" value="DELETE"> 

             <button type="submit" class="fa fa-times pull-left" id="deleteFileButton"></button> 
            </form> 

            <a class="col-xs-10" href="{{$truckingDelivery->exception->path}}" target="_blank">View Exception</a> 
           </div> 

routes.phpの

Route::delete('/exception/{id}','[email protected]'); 

例外モデル

public function delete(){ 

    \File::delete([ 

     $this->path, 

     $this->name 

    ]); 

    parent::delete(); 
} 

トラック運送デリバリ・モデル

public function exception() 
{ 

    return $this->hasOne('App\Exception', 'trucking_delivery_id'); 
} 

輸送デリバリコントローラ

public function deleteException($id){ 

    $exception = Exception::findOrFail($id)->delete(); 

    return back();  

} 

答えて

0

破壊は、(物体またはモデルを介して)直接エンティティを除去するための正しい方法です。

public function deleteException($id){ 

    $exception = Exception::destroy($id); 

    return back();  

} 
+0

動作しませんでした – lispticknvodka

+0

モデルでdelete()関数が呼び出されています。この方法は、私のウェブサイト上の他のすべてのアップロードで機能します。 – lispticknvodka

+0

私のExceptionモデルの保護された静的関数boot(){}がこれに影響を与えているのだろうか?それなしのページには表示されません。 – lispticknvodka

関連する問題