This commit is contained in:
2025-05-11 03:45:17 +08:00
commit 3d7660a24c
70 changed files with 13635 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
*.sqlite*
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}
@@ -0,0 +1,106 @@
<?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('users', function (Blueprint $table) {
$table->id(); // 使用者主鍵ID
$table->string('name'); // 使用者姓名
$table->string('email')->unique(); // 使用者電子郵件,唯一值
$table->timestamp('email_verified_at')->nullable(); // 驗證郵件時間
$table->string('password'); // 密碼
$table->string('phone')->nullable(); // 電話號碼,可為空
$table->enum('role', ['admin', 'coach', 'member'])->default('member'); // 角色:管理員、教練、會員
$table->boolean('is_active')->default(true); // 是否啟用
$table->rememberToken(); // 記住我 token
$table->timestamps(); // 建立與更新時間
});
// 管理員資訊表
Schema::create('admin_profiles', function (Blueprint $table) {
$table->id(); // 管理員資訊主鍵ID
$table->foreignId('user_id')->constrained()->onDelete('cascade'); // 關聯 users 表
$table->string('position')->nullable(); // 職位
$table->string('department')->nullable(); // 部門
$table->text('permissions')->nullable(); // 可使用JSON儲存權限
$table->timestamps(); // 建立與更新時間
});
// 教練資訊表
Schema::create('coach_profiles', function (Blueprint $table) {
$table->id(); // 教練資訊主鍵ID
$table->foreignId('user_id')->constrained()->onDelete('cascade'); // 關聯 users 表
$table->text('bio')->nullable(); // 教練簡介
$table->string('expertise')->nullable(); // 專長領域
$table->string('certification')->nullable(); // 認證資訊
$table->string('avatar')->nullable(); // 頭像
$table->boolean('is_featured')->default(false); // 是否為特色教練
$table->timestamps(); // 建立與更新時間
});
// 會員資訊表
Schema::create('member_profiles', function (Blueprint $table) {
$table->id(); // 會員資訊主鍵ID
$table->foreignId('user_id')->constrained()->onDelete('cascade'); // 關聯 users 表
$table->date('birthday')->nullable(); // 生日
$table->enum('gender', ['male', 'female', 'other'])->nullable(); // 性別
$table->text('address')->nullable(); // 地址
$table->string('emergency_contact')->nullable(); // 緊急聯絡人
$table->string('emergency_phone')->nullable(); // 緊急聯絡電話
$table->timestamps(); // 建立與更新時間
});
// 會員方案表
Schema::create('plans', function (Blueprint $table) {
$table->id(); // 方案主鍵ID
$table->string('name'); // 方案名稱
$table->text('description')->nullable(); // 方案描述
$table->decimal('price', 10, 2); // 價格
$table->integer('duration_days'); // 天數
$table->boolean('is_active')->default(true); // 是否啟用
$table->timestamps(); // 建立與更新時間
});
// 會員訂閱表
Schema::create('subscriptions', function (Blueprint $table) {
$table->id(); // 訂閱主鍵ID
$table->foreignId('user_id')->constrained()->onDelete('cascade'); // 關聯 users 表
$table->foreignId('plan_id')->constrained(); // 關聯 plans 表
$table->date('start_date'); // 訂閱開始日期
$table->date('end_date'); // 訂閱結束日期
$table->enum('status', ['active', 'expired', 'cancelled'])->default('active'); // 訂閱狀態
$table->timestamps(); // 建立與更新時間
});
// 教練與會員關聯表
Schema::create('coach_member', function (Blueprint $table) {
$table->id(); // 關聯主鍵ID
$table->foreignId('coach_id')->constrained('users'); // 關聯教練(users表)
$table->foreignId('member_id')->constrained('users'); // 關聯會員(users表)
$table->timestamps(); // 建立與更新時間
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('coach_member');
Schema::dropIfExists('subscriptions');
Schema::dropIfExists('plans');
Schema::dropIfExists('member_profiles');
Schema::dropIfExists('coach_profiles');
Schema::dropIfExists('admin_profiles');
Schema::dropIfExists('users');
}
};
@@ -0,0 +1,33 @@
<?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('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('personal_access_tokens');
}
};
@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('diving_offers', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestampTz('created_at')->nullable();
$table->string('title');
$table->string('location');
$table->string('spot');
$table->float('rating', 2, 1)->default(0);
$table->integer('reviews')->default(0);
$table->integer('price')->default(0);
$table->text('badges')->nullable(); // 可存 json 或逗號分隔字串
$table->text('description')->nullable();
$table->string('tag')->nullable(); // 可存單一或逗號分隔
$table->string('region')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('diving_offers');
}
};
@@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('social_accounts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id')->comment('本地 user 對應 id');
$table->string('provider')->comment('第三方登入來源,如 google');
$table->string('provider_id')->comment('第三方平台的唯一識別碼');
$table->string('provider_email')->nullable()->comment('第三方平台的 email');
$table->string('provider_name')->nullable()->comment('第三方平台顯示名稱');
$table->string('avatar')->nullable()->comment('第三方平台頭像網址');
$table->text('access_token')->nullable()->comment('第三方 access token');
$table->text('refresh_token')->nullable()->comment('第三方 refresh token');
$table->integer('expires_in')->nullable()->comment('token 有效秒數');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->unique(['provider', 'provider_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('social_accounts');
}
};
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace Database\Seeders;
use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
}
}