diff --git a/app/Models/File.php b/app/Models/File.php index 48b9922c..0a754f42 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -1,8 +1,9 @@ belongsTo('App\Folder', 'folder_id', 'unique_id'); + return $this->belongsTo(Folder::class, 'folder_id', 'unique_id'); } /** - * Get folder - * * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function folder() { - return $this->hasOne('App\Folder', 'unique_id', 'folder_id'); + return $this->hasOne(Folder::class, 'unique_id', 'folder_id'); } /** - * Get sharing attributes - * * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function shared() { - return $this->hasOne('App\Share', 'item_id', 'unique_id'); + return $this->hasOne(Share::class, 'item_id', 'unique_id'); } /** diff --git a/app/Models/Folder.php b/app/Models/Folder.php index 6d7cb1c8..34e3462a 100644 --- a/app/Models/Folder.php +++ b/app/Models/Folder.php @@ -1,21 +1,18 @@ belongsTo('App\Folder', 'parent_id', 'unique_id'); + return $this->belongsTo(Folder::class, 'parent_id', 'unique_id'); } public function folderIds() @@ -130,7 +127,7 @@ class Folder extends Model */ public function files() { - return $this->hasMany('App\File', 'folder_id', 'unique_id'); + return $this->hasMany(File::class, 'folder_id', 'unique_id'); } /** @@ -141,7 +138,7 @@ class Folder extends Model public function trashed_files() { - return $this->hasMany('App\File', 'folder_id', 'unique_id')->withTrashed(); + return $this->hasMany(File::class, 'folder_id', 'unique_id')->withTrashed(); } /** @@ -171,7 +168,7 @@ class Folder extends Model */ public function children() { - return $this->hasMany('App\Folder', 'parent_id', 'unique_id'); + return $this->hasMany(Folder::class, 'parent_id', 'unique_id'); } /** @@ -181,7 +178,7 @@ class Folder extends Model */ public function trashed_children() { - return $this->hasMany('App\Folder', 'parent_id', 'unique_id')->withTrashed(); + return $this->hasMany(Folder::class, 'parent_id', 'unique_id')->withTrashed(); } /** @@ -191,7 +188,7 @@ class Folder extends Model */ public function shared() { - return $this->hasOne('App\Share', 'item_id', 'unique_id'); + return $this->hasOne(Share::class, 'item_id', 'unique_id'); } // Delete all folder children diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index b38f1a5b..f663d49d 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1,47 +1,9 @@ where('parent_id', 0) ->where('user_id', $this->id) ->sortable() @@ -247,7 +243,7 @@ class User extends Authenticatable */ public function favourite_folders() { - return $this->belongsToMany(FileManagerFolder::class, 'favourite_folder', 'user_id', 'folder_unique_id', 'id', 'unique_id')->with('shared:token,id,item_id,permission,protected,expire_in'); + return $this->belongsToMany(Folder::class, 'favourite_folder', 'user_id', 'folder_unique_id', 'id', 'unique_id')->with('shared:token,id,item_id,permission,protected,expire_in'); } /** @@ -257,7 +253,7 @@ class User extends Authenticatable */ public function latest_uploads() { - return $this->hasMany(FileManagerFile::class)->with(['parent'])->take(40); + return $this->hasMany(File::class)->with(['parent'])->take(40); } /** @@ -267,7 +263,7 @@ class User extends Authenticatable */ public function files() { - return $this->hasMany(FileManagerFile::class); + return $this->hasMany(File::class); } /** @@ -277,7 +273,7 @@ class User extends Authenticatable */ public function files_with_trashed() { - return $this->hasMany(FileManagerFile::class)->withTrashed(); + return $this->hasMany(File::class)->withTrashed(); } /** diff --git a/app/Models/UserSettings.php b/app/Models/UserSettings.php index 6cb38157..f72d5e95 100644 --- a/app/Models/UserSettings.php +++ b/app/Models/UserSettings.php @@ -1,6 +1,6 @@ $this->faker->uuid, 'user_id' => $this->faker->uuid, - 'name' => $this->faker->name, + 'name' => $this->faker->word, + 'basename' => Str::slug($this->faker->name), + 'mimetype' => $this->faker->mimeType, + 'filesize' => $this->faker->numberBetween(10000, 99999), 'type' => $this->faker->randomElement( ['image', 'file', 'video', 'audio'] ), diff --git a/database/factories/FolderFactory.php b/database/factories/FolderFactory.php index 26588b7d..3268c16a 100644 --- a/database/factories/FolderFactory.php +++ b/database/factories/FolderFactory.php @@ -2,7 +2,7 @@ namespace Database\Factories; -use App\Folder; +use App\Models\Folder; use Illuminate\Database\Eloquent\Factories\Factory; class FolderFactory extends Factory diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 4b264449..a6d6185b 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -3,7 +3,6 @@ namespace Database\Factories; use App\Models\User; -use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; diff --git a/database/migrations/2019_08_15_171328_create_file_manager_folders.php b/database/migrations/2019_08_15_171328_create_file_manager_folders.php index 75a11f18..38b0e631 100644 --- a/database/migrations/2019_08_15_171328_create_file_manager_folders.php +++ b/database/migrations/2019_08_15_171328_create_file_manager_folders.php @@ -16,7 +16,7 @@ class CreateFileManagerFolders extends Migration Schema::create('folders', function (Blueprint $table) { $table->uuid('id')->primary(); $table->uuid('user_id'); - $table->uuid('parent_id'); + $table->uuid('parent_id')->nullable(); $table->text('name'); $table->string('color')->nullable(); $table->string('emoji')->nullable(); diff --git a/database/migrations/2019_08_15_171345_create_file_manager_files.php b/database/migrations/2019_08_15_171345_create_file_manager_files.php index 70c96e09..4f589868 100644 --- a/database/migrations/2019_08_15_171345_create_file_manager_files.php +++ b/database/migrations/2019_08_15_171345_create_file_manager_files.php @@ -16,7 +16,7 @@ class CreateFileManagerFiles extends Migration Schema::create('files', function (Blueprint $table) { $table->uuid('id')->primary(); $table->uuid('user_id'); - $table->uuid('folder_id'); + $table->uuid('folder_id')->nullable(); $table->text('thumbnail')->nullable(); $table->text('name'); diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php index e85ee9e6..2247c4c6 100644 --- a/tests/Feature/UserTest.php +++ b/tests/Feature/UserTest.php @@ -2,10 +2,10 @@ namespace Tests\Feature; +use App\Models\File; +use App\Models\Folder; use App\Models\User; use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Foundation\Testing\WithFaker; use Laravel\Sanctum\Sanctum; use Tests\TestCase;