Skip to content

Commit

Permalink
Populated all the models and the migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed May 17, 2024
1 parent 697597f commit e246d6a
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/Models/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
class Faq extends Model
{
use HasFactory;

protected $fillable = [
'question', 'answer',
];
}
18 changes: 18 additions & 0 deletions app/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
11 changes: 11 additions & 0 deletions app/Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

22 changes: 22 additions & 0 deletions app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 10 additions & 0 deletions app/Models/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions app/Models/Referral.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

20 changes: 18 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions database/migrations/2024_05_17_123252_create_faqs_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
6 changes: 6 additions & 0 deletions database/migrations/2024_05_17_123252_create_orders_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit e246d6a

Please sign in to comment.