diff --git a/config/subscription.php b/config/subscription.php index 25058db..da97947 100644 --- a/config/subscription.php +++ b/config/subscription.php @@ -1,5 +1,5 @@ \App\Models\User::class, +]; diff --git a/database/migrations/2024_01_14_153551_create_subscriptions_table.php b/database/migrations/2024_01_14_153551_create_subscriptions_table.php new file mode 100644 index 0000000..7ba195f --- /dev/null +++ b/database/migrations/2024_01_14_153551_create_subscriptions_table.php @@ -0,0 +1,36 @@ +id(); + $table->json('title'); + $table->integer('duration_day')->default(-1); + $table->unsignedInteger('price')->default(0); + $table->unsignedInteger('discount_percent')->default(0); + $table->string('sku_code'); + $table->string('type')->default('subscription'); + $table->integer('count')->default(0); + $table->json('description')->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('subscriptions'); + } +}; diff --git a/database/migrations/2024_01_14_153625_create_subscription_user_table.php b/database/migrations/2024_01_14_153625_create_subscription_user_table.php new file mode 100644 index 0000000..2359665 --- /dev/null +++ b/database/migrations/2024_01_14_153625_create_subscription_user_table.php @@ -0,0 +1,30 @@ +id(); + $table->unsignedInteger('user_id'); + $table->unsignedInteger('subscription_id'); + $table->timestamp('expiry_at')->nullable(); + $table->timestamp('created_at'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('subscription_user'); + } +}; diff --git a/database/migrations/2024_01_14_164441_create_subscription_abilities_table.php b/database/migrations/2024_01_14_164441_create_subscription_abilities_table.php new file mode 100644 index 0000000..2ae7222 --- /dev/null +++ b/database/migrations/2024_01_14_164441_create_subscription_abilities_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('slug'); + $table->string('name'); + $table->string('condition_class')->nullable(); + $table->unsignedInteger('subscription_id')->nullable(); + $table->string('description')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('subscription_abilities'); + } +}; diff --git a/routes/api.php b/routes/api.php index 01fd804..b3efdbe 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,11 +1,11 @@ group(function() { - Route::namespace("IICN\Subscription\Controllers")->group(function() { +Route::prefix('api/v1/subscription')->group(function () { + Route::namespace("IICN\Subscription\Controllers")->group(function () { - Route::namespace("Test")->group(function() { + Route::namespace('Test')->group(function () { Route::get('test', 'Test'); }); - + }); -}); \ No newline at end of file +}); diff --git a/src/Middlware/.keep b/src/Middlware/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/database/migrations/.keep b/src/Middlwares/.keep similarity index 100% rename from database/migrations/.keep rename to src/Middlwares/.keep diff --git a/src/Models/Subscription.php b/src/Models/Subscription.php new file mode 100644 index 0000000..f7d90e1 --- /dev/null +++ b/src/Models/Subscription.php @@ -0,0 +1,41 @@ + + */ + protected $fillable = [ + 'title', + 'duration_day', + 'price', + 'discount_percent', + 'sku_code', + 'type', + 'count', + 'description', + ]; + + public function users(): BelongsToMany + { + return $this->belongsToMany(config('subscription.user_model'), 'subscription_user')->with(['created_at', 'expiry_at']); + } + + public function activeUsers(): BelongsToMany + { + return $this->belongsToMany(config('subscription.user_model'), 'subscription_user') + ->wherePivot('expiry_at', '>', Carbon::now()) + ->with(['created_at', 'expiry_at']); + } +} diff --git a/src/Models/SubscriptionAbility.php b/src/Models/SubscriptionAbility.php new file mode 100644 index 0000000..3b4c75a --- /dev/null +++ b/src/Models/SubscriptionAbility.php @@ -0,0 +1,27 @@ + + */ + protected $fillable = [ + 'slug', + 'name', + 'condition_class', + 'subscription_id', + 'description', + ]; + + public function subscription(): BelongsTo + { + return $this->belongsTo(Subscription::class); + } +} diff --git a/src/SubscriptionServiceProvider.php b/src/SubscriptionServiceProvider.php index 59b5060..4b2260c 100644 --- a/src/SubscriptionServiceProvider.php +++ b/src/SubscriptionServiceProvider.php @@ -1,4 +1,5 @@ publish(); } + /** * Register the service provider. * @@ -36,36 +36,31 @@ class SubscriptionServiceProvider extends ServiceProvider /** * publishes the service provider. - * - * @return void */ public function publish(): void { $this->publishes([ __DIR__.'/../config/subscription.php' => config_path('subscription.php'), ]); - + $this->publishes([ __DIR__.'/../lang' => $this->app->langPath('vendor/subscription'), ]); $this->publishes([ - __DIR__.'/../database/migrations/' => database_path('migrations') + __DIR__.'/../database/migrations/' => database_path('migrations'), ], 'subscription-migrations'); } /** * runningInConsole the service provider. - * - * @return void */ public function runningInConsole(): void { if ($this->app->runningInConsole()) { // $this->commands([ - + // ]); } } - -} \ No newline at end of file +}