diff --git a/app/Models/Faq.php b/app/Models/Faq.php index c499d2e..49c16c7 100644 --- a/app/Models/Faq.php +++ b/app/Models/Faq.php @@ -8,4 +8,8 @@ class Faq extends Model { use HasFactory; + + protected $fillable = [ + 'question', 'answer', + ]; } diff --git a/app/Models/Message.php b/app/Models/Message.php index b9f7393..6d2b421 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -4,8 +4,26 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Message extends Model { use HasFactory; + + protected $fillable = [ + 'sender_id', + 'receiver_id', + 'content', + 'read_at' + ]; + + public function sender(): BelongsTo + { + return $this->belongsTo(User::class, 'sender_id'); + } + + public function receiver(): BelongsTo + { + return $this->belongsTo(User::class, 'receiver_id'); + } } diff --git a/app/Models/Notification.php b/app/Models/Notification.php index 71fce82..4586091 100644 --- a/app/Models/Notification.php +++ b/app/Models/Notification.php @@ -4,8 +4,19 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Notification extends Model { use HasFactory; + + protected $fillable = [ + 'user_id', 'from', 'title', 'content', 'read_at', + ]; + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } } + diff --git a/app/Models/Order.php b/app/Models/Order.php index 70b5c62..88cdeee 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -4,8 +4,30 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; class Order extends Model { use HasFactory; + + protected $fillable = [ + 'user_id', 'title', 'description', 'status', 'total_price', + ]; + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + + public function messages(): HasMany + { + return $this->hasMany(Message::class); + } + + public function payment(): HasOne + { + return $this->hasOne(Payment::class); + } } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 58ab47f..eb19c15 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -4,8 +4,18 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Payment extends Model { use HasFactory; + + protected $fillable = [ + 'order_id', 'amount', 'payment_method', 'status', + ]; + + public function order(): BelongsTo + { + return $this->belongsTo(Order::class); + } } diff --git a/app/Models/Referral.php b/app/Models/Referral.php index a4eb72a..1a0b31e 100644 --- a/app/Models/Referral.php +++ b/app/Models/Referral.php @@ -4,8 +4,19 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Referral extends Model { use HasFactory; + + protected $fillable = [ + 'referrer_id', 'referred_email', 'discount_amount', + ]; + + public function referrer(): BelongsTo + { + return $this->belongsTo(User::class, 'referrer_id'); + } } + diff --git a/app/Models/User.php b/app/Models/User.php index 6f528e9..4460789 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,12 +2,13 @@ namespace App\Models; -// use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -class User extends Authenticatable +class User extends Authenticatable implements MustVerifyEmail { use HasFactory, Notifiable; @@ -23,6 +24,21 @@ class User extends Authenticatable 'password', ]; + public function orders(): HasMany + { + return $this->hasMany(Order::class); + } + + public function messages(): HasMany + { + return $this->hasMany(Message::class); + } + + public function referrals(): HasMany + { + return $this->hasMany(Referral::class, 'referrer_id'); + } + /** * The attributes that should be hidden for serialization. * diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 05fb5d9..ff2c271 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -15,6 +15,7 @@ public function up(): void $table->id(); $table->string('name'); $table->string('email')->unique(); + $table->enum('role', ['writer', 'client'])->default('client'); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); diff --git a/database/migrations/2024_05_17_123252_create_faqs_table.php b/database/migrations/2024_05_17_123252_create_faqs_table.php index 29cadfd..953be66 100644 --- a/database/migrations/2024_05_17_123252_create_faqs_table.php +++ b/database/migrations/2024_05_17_123252_create_faqs_table.php @@ -13,6 +13,8 @@ public function up(): void { Schema::create('faqs', function (Blueprint $table) { $table->id(); + $table->text('question'); + $table->text('answer')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/2024_05_17_123252_create_notifications_table.php b/database/migrations/2024_05_17_123252_create_notifications_table.php index ced23a8..df379b4 100644 --- a/database/migrations/2024_05_17_123252_create_notifications_table.php +++ b/database/migrations/2024_05_17_123252_create_notifications_table.php @@ -13,6 +13,11 @@ public function up(): void { Schema::create('notifications', function (Blueprint $table) { $table->id(); + $table->foreignId('user_id')->constrained()->onDelete('cascade'); + $table->string('from'); + $table->string('title'); + $table->text('content'); + $table->timestamp('read_at')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/2024_05_17_123252_create_orders_table.php b/database/migrations/2024_05_17_123252_create_orders_table.php index 6d50d34..6b3a669 100644 --- a/database/migrations/2024_05_17_123252_create_orders_table.php +++ b/database/migrations/2024_05_17_123252_create_orders_table.php @@ -13,10 +13,16 @@ public function up(): void { Schema::create('orders', function (Blueprint $table) { $table->id(); + $table->foreignId('user_id')->constrained()->onDelete('cascade'); + $table->string('title'); + $table->text('description'); + $table->enum('status', ['pending', 'in-progress', 'completed'])->default('pending'); + $table->decimal('total_price', 8, 2); $table->timestamps(); }); } + /** * Reverse the migrations. */ diff --git a/database/migrations/2024_05_17_123252_create_payments_table.php b/database/migrations/2024_05_17_123252_create_payments_table.php index d7c31e5..346fd7f 100644 --- a/database/migrations/2024_05_17_123252_create_payments_table.php +++ b/database/migrations/2024_05_17_123252_create_payments_table.php @@ -13,6 +13,10 @@ public function up(): void { Schema::create('payments', function (Blueprint $table) { $table->id(); + $table->foreignId('order_id')->constrained()->onDelete('cascade'); + $table->decimal('amount', 8, 2); + $table->enum('payment_method', ['paypal', 'cash app', 'zelle']); + $table->enum('status', ['pending', 'completed'])->default('pending'); $table->timestamps(); }); } diff --git a/database/migrations/2024_05_17_123252_create_referrals_table.php b/database/migrations/2024_05_17_123252_create_referrals_table.php index 0c84d32..01f43ba 100644 --- a/database/migrations/2024_05_17_123252_create_referrals_table.php +++ b/database/migrations/2024_05_17_123252_create_referrals_table.php @@ -9,10 +9,13 @@ /** * Run the migrations. */ - public function up(): void + public function up() { Schema::create('referrals', function (Blueprint $table) { $table->id(); + $table->foreignId('referrer_id')->constrained('users')->onDelete('cascade'); + $table->string('referred_email'); + $table->decimal('discount_amount', 8, 2); $table->timestamps(); }); } diff --git a/database/migrations/2024_05_17_123252_create_messages_table.php b/database/migrations/2024_05_17_123255_create_messages_table.php similarity index 66% rename from database/migrations/2024_05_17_123252_create_messages_table.php rename to database/migrations/2024_05_17_123255_create_messages_table.php index c82dd59..69fa9ee 100644 --- a/database/migrations/2024_05_17_123252_create_messages_table.php +++ b/database/migrations/2024_05_17_123255_create_messages_table.php @@ -13,10 +13,15 @@ public function up(): void { Schema::create('messages', function (Blueprint $table) { $table->id(); + $table->foreignId('sender_id')->constrained('users')->onDelete('cascade'); + $table->foreignId('receiver_id')->constrained('users')->onDelete('cascade'); + $table->text('content'); + $table->timestamp('read_at')->nullable(); $table->timestamps(); }); } + /** * Reverse the migrations. */