diff --git a/database/migrations/2017_01_01_112200_create_files_table.php b/database/migrations/2017_01_01_112200_create_files_table.php index 39b1926..93205c5 100644 --- a/database/migrations/2017_01_01_112200_create_files_table.php +++ b/database/migrations/2017_01_01_112200_create_files_table.php @@ -11,7 +11,7 @@ public function up() Schema::create('files', function (Blueprint $table) { $table->id(); - $table->bigInteger('type_id')->unsigned(); + $table->unsignedBigInteger('type_id'); $table->foreign('type_id')->references('id')->on('file_types'); $table->nullableMorphs('attachable'); @@ -23,7 +23,7 @@ public function up() $table->boolean('is_public'); - $table->integer('created_by')->unsigned()->nullable(); + $table->unsignedInteger('created_by')->nullable(); $table->foreign('created_by')->references('id')->on('users'); $table->timestamps(); diff --git a/database/migrations/2017_01_01_112400_create_uploads_table.php b/database/migrations/2017_01_01_112400_create_uploads_table.php index 0063b33..7f4078b 100644 --- a/database/migrations/2017_01_01_112400_create_uploads_table.php +++ b/database/migrations/2017_01_01_112400_create_uploads_table.php @@ -11,7 +11,7 @@ public function up() Schema::create('uploads', function (Blueprint $table) { $table->increments('id'); - $table->bigInteger('file_id')->unsigned()->nullable()->unique(); + $table->unsignedBigInteger('file_id')->nullable()->unique(); $table->foreign('file_id')->references('id')->on('files') ->onUpdate('restrict')->onDelete('restrict'); diff --git a/database/migrations/2017_01_01_112600_create_favorite_files_table.php b/database/migrations/2017_01_01_112600_create_favorite_files_table.php index 6395d41..2cd6688 100644 --- a/database/migrations/2017_01_01_112600_create_favorite_files_table.php +++ b/database/migrations/2017_01_01_112600_create_favorite_files_table.php @@ -11,10 +11,10 @@ public function up() Schema::create('favorite_files', function (Blueprint $table) { $table->id(); - $table->integer('user_id')->unsigned()->index(); + $table->unsignedInteger('user_id')->index(); $table->foreign('user_id')->references('id')->on('users'); - $table->bigInteger('file_id')->unsigned()->index(); + $table->unsignedBigInteger('file_id')->index(); $table->foreign('file_id')->references('id')->on('files') ->onUpdate('restrict')->onDelete('restrict'); diff --git a/src/EnumServiceProvider.php b/src/EnumServiceProvider.php index 10c809f..544ee9d 100644 --- a/src/EnumServiceProvider.php +++ b/src/EnumServiceProvider.php @@ -3,11 +3,8 @@ namespace LaravelEnso\Files; use LaravelEnso\Enums\EnumServiceProvider as ServiceProvider; -use LaravelEnso\Files\Enums\TemporaryLinkDuration; class EnumServiceProvider extends ServiceProvider { - public $register = [ - 'temporaryLinkDuration' => TemporaryLinkDuration::class, - ]; + public $register = []; } diff --git a/src/Enums/TemporaryLinkDuration.php b/src/Enums/TemporaryLinkDuration.php index e06395b..0316486 100644 --- a/src/Enums/TemporaryLinkDuration.php +++ b/src/Enums/TemporaryLinkDuration.php @@ -2,20 +2,26 @@ namespace LaravelEnso\Files\Enums; -use LaravelEnso\Enums\Services\Enum; +use LaravelEnso\Enums\Contracts\Frontend; +use LaravelEnso\Enums\Contracts\Mappable; -class TemporaryLinkDuration extends Enum +enum TemporaryLinkDuration: int implements Mappable, Frontend { - public const FiveMinutes = 5 * 60; - public const OneHour = 60 * 60; - public const OneDay = 60 * 60 * 24; + case FiveMinutes = 5 * 60; + case OneHour = 60 * 60; + case OneDay = 60 * 60 * 24; - public static function data(): array + public function map(): string { - return [ + return match ($this) { self::FiveMinutes => '5m', self::OneHour => '1h', self::OneDay => '24h', - ]; + }; + } + + public static function registerBy(): string + { + return 'temporaryLinkDuration'; } } diff --git a/src/Http/Requests/ValidateLink.php b/src/Http/Requests/ValidateLink.php index d6000f7..0b5075a 100644 --- a/src/Http/Requests/ValidateLink.php +++ b/src/Http/Requests/ValidateLink.php @@ -3,6 +3,7 @@ namespace LaravelEnso\Files\Http\Requests; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Rule; use LaravelEnso\Files\Enums\TemporaryLinkDuration; class ValidateLink extends FormRequest @@ -15,7 +16,7 @@ public function authorize() public function rules() { return [ - 'seconds' => 'required|in:'.TemporaryLinkDuration::keys()->implode(','), + 'seconds' => Rule::enum(TemporaryLinkDuration::class), ]; } }