Exemplo n.º 1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $file = File::findOrFail($id);
     exec("rm /public/{$file->path_to_file}");
     $file->delete();
     return back();
 }
Exemplo n.º 2
0
 /**
  * @param string $hash
  * @param string $tag
  *
  * @return bool
  * @throws \Exception
  */
 public function deleteFile($hash, $tag = '')
 {
     /** @var \App\Models\File $file */
     $file = File::findOrFail($hash);
     if ($file->load('uploaders')->count()) {
         /** @var \App\Models\User $me */
         $me = app('sentinel')->getUser();
         if ($file->uploaders->contains('id', $me->id)) {
             $pivotToDelete = $file->uploaders()->newPivotStatement()->where('user_id', '=', $me->id);
             if (!empty($tag)) {
                 $pivotToDelete->where('tag', '=', $tag);
             }
             $pivotToDelete->delete();
             $file->load('uploaders');
         }
         !$file->uploaders->count() && app('filesystem')->disk($file->disk)->delete($file->path) && $file->delete();
     }
     return true;
 }