mirror of
https://github.com/nihonbuzz/nihonbuzz-academy.git
synced 2026-01-26 05:25:37 +07:00
first commit
This commit is contained in:
43
app/Models/Course.php
Normal file
43
app/Models/Course.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Course extends Model
|
||||
{
|
||||
use HasFactory, HasUuids, SoftDeletes;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'metadata' => 'array',
|
||||
'is_published' => 'boolean',
|
||||
'price' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function level(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Level::class);
|
||||
}
|
||||
|
||||
public function enrollments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Enrollment::class);
|
||||
}
|
||||
|
||||
public function modules(): HasMany
|
||||
{
|
||||
return $this->hasMany(Module::class)->orderBy('order_index');
|
||||
}
|
||||
|
||||
public function teacher(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'teacher_id');
|
||||
}
|
||||
}
|
||||
28
app/Models/Enrollment.php
Normal file
28
app/Models/Enrollment.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Enrollment extends Model
|
||||
{
|
||||
use HasUuids;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'enrolled_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function course(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Course::class);
|
||||
}
|
||||
}
|
||||
26
app/Models/Lesson.php
Normal file
26
app/Models/Lesson.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Lesson extends Model
|
||||
{
|
||||
use HasFactory, HasUuids, SoftDeletes;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'metadata' => 'array',
|
||||
'is_free_preview' => 'boolean',
|
||||
];
|
||||
|
||||
public function module(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Module::class);
|
||||
}
|
||||
}
|
||||
24
app/Models/Level.php
Normal file
24
app/Models/Level.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Level extends Model
|
||||
{
|
||||
use HasFactory, HasUuids;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function courses(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Course::class);
|
||||
}
|
||||
|
||||
public function vocabularies(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Vocabulary::class);
|
||||
}
|
||||
}
|
||||
32
app/Models/Module.php
Normal file
32
app/Models/Module.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Module extends Model
|
||||
{
|
||||
use HasFactory, HasUuids, SoftDeletes;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'metadata' => 'array',
|
||||
'is_free_preview' => 'boolean',
|
||||
];
|
||||
|
||||
public function course(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Course::class);
|
||||
}
|
||||
|
||||
public function lessons(): HasMany
|
||||
{
|
||||
return $this->hasMany(Lesson::class)->orderBy('order_index');
|
||||
}
|
||||
}
|
||||
15
app/Models/Permission.php
Normal file
15
app/Models/Permission.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Spatie\Permission\Models\Permission as SpatiePermission;
|
||||
|
||||
class Permission extends SpatiePermission
|
||||
{
|
||||
use HasUuids;
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
public $incrementing = false;
|
||||
protected $keyType = 'string';
|
||||
}
|
||||
15
app/Models/Role.php
Normal file
15
app/Models/Role.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Spatie\Permission\Models\Role as SpatieRole;
|
||||
|
||||
class Role extends SpatieRole
|
||||
{
|
||||
use HasUuids;
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
public $incrementing = false;
|
||||
protected $keyType = 'string';
|
||||
}
|
||||
28
app/Models/SocialAccount.php
Normal file
28
app/Models/SocialAccount.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
|
||||
class SocialAccount extends Model
|
||||
{
|
||||
use HasUuids;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'provider',
|
||||
'provider_id',
|
||||
'token',
|
||||
'refresh_token',
|
||||
'expires_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the user that owns the social account.
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
33
app/Models/SrsReview.php
Normal file
33
app/Models/SrsReview.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SrsReview extends Model
|
||||
{
|
||||
use HasFactory, HasUuids;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'vocabulary_id', 'ease_factor', 'interval',
|
||||
'repetitions', 'next_review_at', 'last_review_at', 'status'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'ease_factor' => 'decimal:2',
|
||||
'next_review_at' => 'datetime',
|
||||
'last_review_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function vocabulary()
|
||||
{
|
||||
return $this->belongsTo(Vocabulary::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
88
app/Models/User.php
Normal file
88
app/Models/User.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
|
||||
class User extends Authenticatable implements FilamentUser
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable, HasRoles, HasUuids;
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return $this->hasAnyRole(['admin', 'super_admin', 'bendahara', 'editor', 'sensei']);
|
||||
}
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'avatar_url',
|
||||
'xp_points',
|
||||
'current_streak',
|
||||
'metadata',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the social accounts for the user.
|
||||
*/
|
||||
public function socialAccounts(): HasMany
|
||||
{
|
||||
return $this->hasMany(SocialAccount::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enrollments for the user.
|
||||
*/
|
||||
public function enrollments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Enrollment::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the progress for the user.
|
||||
*/
|
||||
public function userProgress(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserProgress::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'last_activity_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Models/UserProgress.php
Normal file
31
app/Models/UserProgress.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserProgress extends Model
|
||||
{
|
||||
use HasUuids;
|
||||
|
||||
protected $table = 'user_progress';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'completed_at' => 'datetime',
|
||||
'metadata' => 'array',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function lesson(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Lesson::class);
|
||||
}
|
||||
}
|
||||
27
app/Models/Vocabulary.php
Normal file
27
app/Models/Vocabulary.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Vocabulary extends Model
|
||||
{
|
||||
use HasFactory, HasUuids;
|
||||
|
||||
protected $fillable = [
|
||||
'word', 'reading', 'romaji', 'meaning_en', 'meaning_id',
|
||||
'level_id', 'audio_url', 'type', 'stroke_order_svg', 'example_sentences'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'stroke_order_svg' => 'array',
|
||||
'example_sentences' => 'array',
|
||||
];
|
||||
|
||||
public function reviews()
|
||||
{
|
||||
return $this->hasMany(SrsReview::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user