fix
This commit is contained in:
parent
d63c3775f3
commit
67faa5427b
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'user_model' => \App\Models\User::class,
|
||||
];
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('subscriptions', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('subscription_user', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('subscription_abilities', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
@ -3,7 +3,7 @@
|
||||
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');
|
||||
});
|
||||
|
||||
|
41
src/Models/Subscription.php
Normal file
41
src/Models/Subscription.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace IICN\Subscription\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Subscription extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
}
|
27
src/Models/SubscriptionAbility.php
Normal file
27
src/Models/SubscriptionAbility.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace IICN\Subscription\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SubscriptionAbility extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'slug',
|
||||
'name',
|
||||
'condition_class',
|
||||
'subscription_id',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function subscription(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Subscription::class);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace IICN\Subscription;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
@ -7,8 +8,6 @@ class SubscriptionServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
@ -22,6 +21,7 @@ class SubscriptionServiceProvider extends ServiceProvider
|
||||
|
||||
$this->publish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
@ -36,8 +36,6 @@ class SubscriptionServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* publishes the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function publish(): void
|
||||
{
|
||||
@ -50,14 +48,12 @@ class SubscriptionServiceProvider extends ServiceProvider
|
||||
]);
|
||||
|
||||
$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
|
||||
{
|
||||
@ -67,5 +63,4 @@ class SubscriptionServiceProvider extends ServiceProvider
|
||||
// ]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user