improved seeder customer, area & post

pull/44/head
A1Gard 4 months ago
parent 60698fce0c
commit 2a1e43bc25

@ -19,11 +19,12 @@ class InvoiceFactory extends Factory
public function definition(): array public function definition(): array
{ {
$date = $this->faker->dateTimeBetween('-1 months', 'now'); $date = $this->faker->dateTimeBetween('-1 months', 'now');
$c = Customer::inRandomOrder()->first();
return [ return [
'customer_id' => Customer::inRandomOrder()->first()->id, 'customer_id' => $c->id,
'status' => Invoice::$invoiceStatus[rand(0,count(Invoice::$invoiceStatus)-1)], 'status' => Invoice::$invoiceStatus[rand(0,count(Invoice::$invoiceStatus)-1)],
'desc' => $this->faker->realText(), 'desc' => $this->faker->realText(),
'address_id' => null, 'address_id' => $c->addresses()->inRandomOrder()->first()->id,
'transport_id' => null, 'transport_id' => null,
'transport_price' => 0, 'transport_price' => 0,
'created_at' => $date, 'created_at' => $date,

@ -17,6 +17,7 @@ return new class extends Migration
$table->tinyInteger('max')->default(1); $table->tinyInteger('max')->default(1);
$table->string('icon')->nullable(); $table->string('icon')->nullable();
$table->json('valid_segments'); $table->json('valid_segments');
$table->string('preview')->nullable();
$table->timestamps(); $table->timestamps();
}); });
} }

@ -21,6 +21,7 @@ class AreaSeeder extends Seeder
["preloader"] ["preloader"]
), ),
'max' => 1, 'max' => 1,
'preview' => null,
'icon' => 'ri-loader-2-line', 'icon' => 'ri-loader-2-line',
], ],
[ [
@ -31,6 +32,7 @@ class AreaSeeder extends Seeder
,"groups","categories","category","group","index"] ,"groups","categories","category","group","index"]
), ),
'max' => 10, 'max' => 10,
'preview' => 'welcome',
'icon' => 'ri-layout-top-2-line', 'icon' => 'ri-layout-top-2-line',
], ],
]; ];
@ -40,6 +42,7 @@ class AreaSeeder extends Seeder
$a->max = $area['max']; $a->max = $area['max'];
$a->valid_segments = $area['valid_segments']; $a->valid_segments = $area['valid_segments'];
$a->icon = $area['icon']; $a->icon = $area['icon'];
$a->preview = $area['preview'];
$a->save(); $a->save();
} }
} }

@ -3,6 +3,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Customer; use App\Models\Customer;
use App\Models\State;
use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
@ -15,5 +16,17 @@ class CustomerSeeder extends Seeder
{ {
// //
Customer::factory(35)->create(); Customer::factory(35)->create();
foreach (Customer::all() as $customer) {
$s = State::inRandomOrder()->first();
$c = $s->cities()->inRandomOrder()->first();
$customer->addresses()->create([
'state_id' => $s->id,
'city_id' => $c->id,
'zip' => rand(12345, 54321),
'lat' => $c->lat,
'lng' => $c->lng,
'address' => 'some address',
]);
}
} }
} }

@ -2,6 +2,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Group;
use App\Models\Post; use App\Models\Post;
use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
@ -15,5 +16,9 @@ class PostSeeder extends Seeder
{ {
// //
Post::factory(55)->create(); Post::factory(55)->create();
foreach (Post::inRandomOrder()->limit(10)->get() as $post) {
$post->groups()->sync(Group::all()->pluck('id')->toArray());
}
} }
} }

@ -1,5 +1,7 @@
@extends('layouts.app') @extends('layouts.app')
@section('title')
{{__("GFX")}} -
@endsection
@section('content') @section('content')
<form action="{{route('admin.gfx.update')}}" method="post" class="mb-5 pb-5"> <form action="{{route('admin.gfx.update')}}" method="post" class="mb-5 pb-5">
@csrf @csrf

Loading…
Cancel
Save