Skip to content

Commit

Permalink
Added deliveries and message attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed May 17, 2024
1 parent e246d6a commit 3c11243
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/Models/Attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Attachment extends Model
{
use HasFactory;

protected $fillable = [
'message_id', 'name', 'path', 'type', 'size',
];

public function message(): BelongsTo
{
return $this->belongsTo(Message::class, 'message_id');
}
}
22 changes: 22 additions & 0 deletions app/Models/Delivery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Delivery extends Model
{
use HasFactory;

protected $fillable = [
'order_id',
'status',
];

public function order(): BelongsTo
{
return $this->belongsTo(Order::class, 'order_id');
}
}
6 changes: 6 additions & 0 deletions app/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Message extends Model
{
Expand All @@ -26,4 +27,9 @@ public function receiver(): BelongsTo
{
return $this->belongsTo(User::class, 'receiver_id');
}

public function attachments(): HasMany
{
return $this->hasMany(Attachment::class);
}
}
23 changes: 23 additions & 0 deletions database/factories/MessageFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Message>
*/
class MessageFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}
1 change: 1 addition & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function definition(): array
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'role' => rand(0, 1) ? 'client' : 'writer',
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
Expand Down
32 changes: 32 additions & 0 deletions database/migrations/2024_05_17_125635_create_attachments_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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('attachments', function (Blueprint $table) {
$table->id();
$table->foreignId('message_id')->constrained()->onDelete('cascade');
$table->string('name');
$table->string('path');
$table->string('type');
$table->integer('size');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('attachments');
}
};
29 changes: 29 additions & 0 deletions database/migrations/2024_05_17_125922_create_deliveries_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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('deliveries', function (Blueprint $table) {
$table->id();
$table->foreignId('order_id')->constrained()->onDelete('cascade');
$table->string('status');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('deliveries');
}
};
Binary file added scholarspace
Binary file not shown.

0 comments on commit 3c11243

Please sign in to comment.