Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add order table and seeder #388

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Concerns\HasUuids;

class Order extends Model
{
use HasFactory, HasUuids;
use HasUuids;
use HasFactory;
}
32 changes: 0 additions & 32 deletions database/migrations/2024_07_28_165629_create_orders_table.php

This file was deleted.

36 changes: 36 additions & 0 deletions database/migrations/2024_08_06_182021_create_orders_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('orders', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->uuid('user_id');
$table->string('order_number')->unique();
$table->decimal('total_amount', 10, 2);
$table->decimal('tax', 10, 2)->nullable();
$table->decimal('shipping_cost', 10, 2)->nullable();
$table->decimal('discount', 10, 2)->nullable();
$table->string('status')->default('pending');
$table->string('payment_status')->default('unpaid');
$table->string('payment_method')->nullable();
$table->string('shipping_address')->nullable();
$table->string('billing_address')->nullable();
$table->text('notes')->nullable();
$table->timestamps();
$table->softDeletes();

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}

public function down(): void
{
Schema::dropIfExists('orders');
}
};
1 change: 1 addition & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function run(): void
FaqSeeder::class,
UserNotificationSeeder::class,
NotificationSettingSeeder::class,
OrderSeeder::class
]);

}
Expand Down
32 changes: 26 additions & 6 deletions database/seeders/OrderSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,36 @@

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Order;
use App\Models\User;
use Faker\Factory as Faker;
use Illuminate\Support\Str;


class OrderSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
public function run()
{
//
$faker = Faker::create();
$users = User::all();

foreach (range(1, 50) as $index) {
Order::create([
'id' => Str::uuid(),
'user_id' => $users->random()->id,
'order_number' => $faker->unique()->numberBetween(100000, 999999),
'total_amount' => $faker->randomFloat(2, 10, 1000),
'tax' => $faker->randomFloat(2, 1, 100),
'shipping_cost' => $faker->randomFloat(2, 5, 50),
'discount' => $faker->randomFloat(2, 0, 50),
'status' => $faker->randomElement(['pending', 'processing', 'shipped', 'delivered']),
'payment_status' => $faker->randomElement(['unpaid', 'paid', 'refunded']),
'payment_method' => $faker->randomElement(['credit_card', 'paypal', 'bank_transfer']),
'shipping_address' => $faker->address,
'billing_address' => $faker->address,
'notes' => $faker->optional()->sentence,
]);
}
}
}
Empty file added isUniqueConstraintError($e))
Empty file.
Empty file added prepareBindings($bindings)
Empty file.
Loading