コード例 #1
0
ファイル: AppServiceProvider.php プロジェクト: dwijpr/share
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     User::created(function (User $user) {
         Folder::create(['name' => '/', 'user_id' => $user->id]);
         Activity::create(['type' => 'user_created', 'user_id' => $user->id]);
     });
     Folder::deleting(function (Folder $folder) {
         foreach ($folder->folders as $_folder) {
             $_folder->_delete();
         }
         foreach ($folder->files as $file) {
             $file->delete();
         }
     });
     File::deleting(function (File $file) {
         $file = updateFile($file, fileInfo($file));
         $filenames = [];
         if ($file->type == 'image') {
             $altImages = ['opt', 'xs'];
             foreach ($altImages as $suffix) {
                 $name = explode('.', $file->filename)[0];
                 $extension = explode('.', $file->filename)[1];
                 array_push($filenames, "{$name}.{$suffix}.{$extension}");
             }
         }
         Storage::delete($file->filename);
         if (!empty($filenames)) {
             foreach ($filenames as $filename) {
                 Storage::delete($filename);
             }
         }
     });
 }
コード例 #2
0
ファイル: FilesController.php プロジェクト: dwijpr/share
 private function _share(FileModel $file, $value, $createActivity = true, $redirect = true)
 {
     $this->authorize('all', $file);
     $file->shared = $value;
     $file->save();
     if ($value) {
         if ($createActivity) {
             Activity::create(['type' => 'file_shared', 'item_id' => $file->id, 'user_id' => $this->user->id]);
         }
         fmsgs(['title' => 'File Shared', 'type' => 'success', 'text' => 'The ' . $file->name . ' file successfully shared!']);
     } else {
         fmsgs(['title' => 'Unshared File', 'type' => 'success', 'text' => 'The ' . $file->name . ' file successfully unshared!']);
     }
     if ($redirect) {
         return redirect()->back();
     }
 }