This commit is contained in:
ct
2025-07-02 18:25:12 +08:00
parent 68a47ec916
commit 0aa0d9569f
20 changed files with 515 additions and 193 deletions

View File

@@ -26,4 +26,11 @@ class Plan extends Model
'name',
'tier',
];
protected $hidden = [
'id',
'created_at',
'updated_at',
'laravel_through_key',
];
}

View File

@@ -3,6 +3,8 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -14,7 +16,7 @@
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasApiTokens, HasFactory, Notifiable, SoftDeletes, Billable;
use Billable, HasApiTokens, HasFactory, Notifiable, SoftDeletes;
/**
* The attributes that are mass assignable.
@@ -37,8 +39,28 @@ class User extends Authenticatable
'password',
'remember_token',
'id',
'created_at',
'updated_at',
'deleted_at',
'uuid',
'stripe_id',
'google_id',
'email_verified_at',
'pm_last_four',
'pm_type',
'trial_ends_at',
'email',
];
protected $appends = ['ids'];
protected function ids(): Attribute
{
return Attribute::make(
get: fn($value, $attributes) => hashids_encode($attributes['id']),
);
}
/**
* Get the attributes that should be cast.
*
@@ -61,4 +83,19 @@ protected static function booted(): void
$model->uuid = $model->uuid ?? (string) Str::uuid();
});
}
public function user_usage()
{
return $this->hasOne(UserUsage::class, 'user_id');
}
public function user_plan()
{
return $this->hasOne(UserPlan::class, 'user_id');
}
public function plan()
{
return $this->hasOneThrough(Plan::class, UserPlan::class, 'user_id', 'id', 'id', 'plan_id');
}
}

View File

@@ -40,4 +40,14 @@ class UserPlan extends Model
'cancel_at',
'canceled_at',
];
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function plan()
{
return $this->belongsTo(Plan::class, 'plan_id');
}
}

View File

@@ -7,30 +7,45 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
/**
* Class UserUsage
*
*
* @property int $id
* @property int $user_id
* @property int $non_watermark_videos_left
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @package App\Models
*/
class UserUsage extends Model
{
protected $table = 'user_usages';
protected $table = 'user_usages';
protected $casts = [
'user_id' => 'int',
'non_watermark_videos_left' => 'int'
];
protected $casts = [
'user_id' => 'int',
'non_watermark_videos_left' => 'int',
];
protected $fillable = [
'user_id',
'non_watermark_videos_left'
];
protected $fillable = [
'user_id',
'non_watermark_videos_left',
];
protected $hidden = [
'created_at',
'updated_at',
'id',
'user_id',
];
protected $appends = ['ids'];
protected function ids(): Attribute
{
return Attribute::make(
get: fn($value, $attributes) => hashids_encode($attributes['id']),
);
}
}