wip
This commit is contained in:
163
database/seeders/AttributeTableSeeder.php
Normal file
163
database/seeders/AttributeTableSeeder.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Ecommerce\Product\Property\Attribute;
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AttributeTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedAttributes();
|
||||
$this->seedAttributeValues();
|
||||
$this->seedProductAttributes();
|
||||
$this->seedAttributeValueProductAttribute();
|
||||
$this->seedAttributeCategory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed "attributes" table
|
||||
*/
|
||||
public function seedAttributes(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/attributes.json'));
|
||||
|
||||
$table = 'attributes';
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'name' => $data->name,
|
||||
'slug' => $data->slug,
|
||||
'description' => $data->description,
|
||||
'type' => $data->type,
|
||||
'is_visible' => $data->is_enabled,
|
||||
'is_required' => $data->is_required,
|
||||
'is_searchable' => $data->is_searchable,
|
||||
'is_filterable' => $data->is_filterable,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['attributes error: ' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed "attribute_values" table
|
||||
*/
|
||||
public function seedAttributeValues(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/attribute_values.json'));
|
||||
|
||||
$table = 'attribute_values';
|
||||
foreach ($datas as $data) {
|
||||
if (DB::table($table)->where('key', $data->key)->exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'value' => $data->value,
|
||||
'key' => $data->key,
|
||||
'attribute_id' => $data->attribute_id,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['attributes error: ' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed "product_attributes" table
|
||||
*/
|
||||
public function seedProductAttributes(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/product_attributes.json'));
|
||||
|
||||
$table = 'product_attributes';
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'product_id' => $data->product_id,
|
||||
'attribute_id' => $data->attribute_id,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['Ignored product attribute', $data->id]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed "attribute_value_product_attribute" table
|
||||
*/
|
||||
public function seedAttributeValueProductAttribute(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/attribute_value_product_attribute.json'));
|
||||
|
||||
$table = 'attribute_value_product_attribute';
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'attribute_value_id' => $data->attribute_value_id,
|
||||
'product_attribute_id' => $data->product_attribute_id,
|
||||
'product_custom_value' => $data->product_custom_value,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['Ignored attribute value product attribute', $data->id]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed "attribute_category" table
|
||||
*/
|
||||
public function seedAttributeCategory(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/attribute_category.json'));
|
||||
|
||||
$table = 'attribute_category';
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'attribute_id' => $data->attribute_id,
|
||||
'category_id' => $data->category_id,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['error attribute' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
50
database/seeders/BannerTableSeeder.php
Normal file
50
database/seeders/BannerTableSeeder.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\System\Settings\OS;
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BannerTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$mobileBanners = json_decode(File::get('database/data/banners.json'));
|
||||
|
||||
$table = 'banners';
|
||||
try {
|
||||
foreach ($mobileBanners as $mobileBanner) {
|
||||
DB::table($table)->insert([
|
||||
'id' => $mobileBanner->id,
|
||||
'app' => OS::MOBILE_APP,
|
||||
'place' => $mobileBanner->place,
|
||||
'link' => $mobileBanner->link,
|
||||
'is_visible' => $mobileBanner->is_visible,
|
||||
'resource_id' => $mobileBanner->banner_resource,
|
||||
'resource_type' => $mobileBanner->banner_type,
|
||||
'sort_order' => $mobileBanner->sort_order,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
47
database/seeders/BrandTableSeeder.php
Normal file
47
database/seeders/BrandTableSeeder.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BrandTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/brands.json'));
|
||||
|
||||
$table = 'brands';
|
||||
foreach ($datas as $data) {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
'name' => $data->name,
|
||||
'slug' => $data->slug,
|
||||
'website' => $data->website,
|
||||
'description' => $data->description,
|
||||
'is_visible' => $data->is_enabled,
|
||||
'seo_title' => $data->seo_title,
|
||||
'seo_description' => $data->seo_description,
|
||||
'type' => $data->type,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
53
database/seeders/CarouselTableSeeder.php
Normal file
53
database/seeders/CarouselTableSeeder.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\System\Settings\OS;
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CarouselTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$mobileCarousels = json_decode(File::get('database/data/carousels.json'));
|
||||
|
||||
$table = 'carousels';
|
||||
|
||||
DB::table($table)->truncate();
|
||||
|
||||
try {
|
||||
foreach ($mobileCarousels as $mobileCarousel) {
|
||||
DB::table($table)->insert([
|
||||
'id' => $mobileCarousel->id,
|
||||
'app' => OS::MOBILE_APP,
|
||||
'place' => $mobileCarousel->place,
|
||||
'link' => $mobileCarousel->link,
|
||||
'is_visible' => $mobileCarousel->is_visible,
|
||||
'resource_id' => $mobileCarousel->banner_resource,
|
||||
'resource_type' => $mobileCarousel->banner_type,
|
||||
'sort_order' => $mobileCarousel->sort_order,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
51
database/seeders/CartItemTableSeeder.php
Normal file
51
database/seeders/CartItemTableSeeder.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Ecommerce\Product\Cart\CartItem;
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CartItemTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
CartItem::truncate();
|
||||
|
||||
$datas = collect(json_decode(File::get('database/data/carts.json')));
|
||||
|
||||
$table = 'cart_items';
|
||||
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'user_id' => $data->user_id,
|
||||
'product_id' => $data->product_id,
|
||||
'product_quantity' => $data->product_quantity,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['cart_items error: ' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
79
database/seeders/CategoryTableSeeder.php
Normal file
79
database/seeders/CategoryTableSeeder.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Ecommerce\Product\Category\Category;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CategoryTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
Category::truncate();
|
||||
|
||||
$datas = collect(json_decode(File::get('database/data/categories.json')));
|
||||
|
||||
// Insert root categories
|
||||
$rootCategories = $datas->whereNull('parent_id');
|
||||
$rootCategories->each(function ($data) {
|
||||
$this->insertCategory($data);
|
||||
});
|
||||
|
||||
// Insert child categories
|
||||
$childCategories = $datas->whereNotNull('parent_id');
|
||||
$restOfCategories = collect();
|
||||
$childCategories->each(function ($data) use ($rootCategories, $restOfCategories) {
|
||||
if ($rootCategories->pluck('id')->contains($data->parent_id)) {
|
||||
$this->insertCategory($data);
|
||||
} else {
|
||||
$restOfCategories->push($data);
|
||||
}
|
||||
});
|
||||
|
||||
$restOfCategories->each(function ($data) use ($rootCategories, $childCategories) {
|
||||
if ($rootCategories->pluck('id')->contains($data->parent_id) || $childCategories->pluck('id')->contains($data->parent_id)) {
|
||||
$this->insertCategory($data);
|
||||
} else {
|
||||
info('Skipping category: '.$data->name);
|
||||
}
|
||||
});
|
||||
|
||||
$table = 'categories';
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
|
||||
// Encapsulate the category insertion logic in a separate function
|
||||
public function insertCategory($data)
|
||||
{
|
||||
DB::table('categories')->insert([
|
||||
'id' => $data->id,
|
||||
'parent_id' => $data->parent_id,
|
||||
'name' => $data->name,
|
||||
'slug' => $data->slug,
|
||||
'type' => $data->type,
|
||||
'description' => $data->description,
|
||||
'seo_title' => $data->seo_title,
|
||||
'seo_description' => $data->seo_description,
|
||||
'is_visible' => $data->is_enabled,
|
||||
'tax_percentage' => $data->tax_percentage,
|
||||
'options' => sprintf('{"color":"%s"}', $data->color),
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
}
|
||||
}
|
||||
67
database/seeders/ChannelTableSeeder.php
Normal file
67
database/seeders/ChannelTableSeeder.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Ecommerce\Channel\Channel;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ChannelTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Started kit
|
||||
*/
|
||||
private function seedStarterKit(): void
|
||||
{
|
||||
collect([
|
||||
[
|
||||
'name' => 'Tmpost',
|
||||
'slug' => 'tmpost',
|
||||
'description' => 'Tmpost default',
|
||||
'timezone' => 'Asia/Ashgabat',
|
||||
'url' => 'http://shop.post.tm',
|
||||
'is_default' => true,
|
||||
],
|
||||
])->each(fn ($data) => Channel::create($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/channels.json'));
|
||||
$relations = collect(json_decode(File::get('database/data/channelables.json')));
|
||||
|
||||
$table = 'channels';
|
||||
foreach ($datas as $data) {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
'name' => $data->name,
|
||||
'slug' => $data->slug,
|
||||
'description' => $data->description,
|
||||
'timezone' => $data->timezone,
|
||||
'url' => $data->url,
|
||||
'is_default' => true,
|
||||
'is_visible' => $data->is_default,
|
||||
'channelables_id' => $relations->firstWhere('channel_id', $data->id)?->channelable_id,
|
||||
'channelables_type' => $relations->firstWhere('channel_id', $data->id)?->channelable_type,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
46
database/seeders/CollectionTableSeeder.php
Normal file
46
database/seeders/CollectionTableSeeder.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CollectionTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/collections.json'));
|
||||
|
||||
$table = 'collections';
|
||||
foreach ($datas as $data) {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
'name' => $data->name,
|
||||
'slug' => $data->slug,
|
||||
'description' => $data->description,
|
||||
'sort_order' => $data->sort_order,
|
||||
'seo_title' => $data->seo_title,
|
||||
'seo_description' => $data->seo_description,
|
||||
'is_visible' => $data->shown_on_homescreen,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
38
database/seeders/ContactUsTableSeeder.php
Normal file
38
database/seeders/ContactUsTableSeeder.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ContactUsTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/contact_us.json'));
|
||||
|
||||
$table = 'contact_us';
|
||||
foreach ($datas as $data) {
|
||||
DB::table($table)->insert([
|
||||
'title' => $data->title,
|
||||
'phone' => $data->phone,
|
||||
'content' => $data->content,
|
||||
'type' => $data->type,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
43
database/seeders/DatabaseSeeder.php
Normal file
43
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
SettingsSeeder::class,
|
||||
RolesTableSeeder::class,
|
||||
BannerTableSeeder::class,
|
||||
CarouselTableSeeder::class,
|
||||
UserTableSeeder::class,
|
||||
ChannelTableSeeder::class,
|
||||
PaymentTypeTableSeeder::class,
|
||||
ProvinceTableSeeder::class,
|
||||
BrandTableSeeder::class,
|
||||
ProductTableSeeder::class,
|
||||
PostBranchTableSeeder::class,
|
||||
InventoriesTableSeeder::class,
|
||||
CategoryTableSeeder::class,
|
||||
CollectionTableSeeder::class,
|
||||
AttributeTableSeeder::class,
|
||||
ContactUsTableSeeder::class,
|
||||
LegalPageTableSeeder::class,
|
||||
ReviewTableSeeder::class,
|
||||
NewsletterTableSeeder::class,
|
||||
CartItemTableSeeder::class,
|
||||
FavouriteTableSeeder::class,
|
||||
MediaTableSeeder::class,
|
||||
ProductHasRelationsTable::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
48
database/seeders/FavouriteTableSeeder.php
Normal file
48
database/seeders/FavouriteTableSeeder.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class FavouriteTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$table = 'favorites';
|
||||
DB::table($table)->delete();
|
||||
|
||||
$datas = collect(json_decode(File::get('database/data/favorites.json')));
|
||||
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'user_id' => $data->user_id,
|
||||
'product_id' => $data->product_id,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
54
database/seeders/InventoriesTableSeeder.php
Normal file
54
database/seeders/InventoriesTableSeeder.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class InventoriesTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/inventories.json'));
|
||||
|
||||
$table = 'inventories';
|
||||
DB::table($table)->truncate();
|
||||
|
||||
try {
|
||||
foreach ($datas as $data) {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'name' => $data->name,
|
||||
'code' => $data->code,
|
||||
'description' => $data->description,
|
||||
'email' => $data->email,
|
||||
'phone_number' => $data->phone_number,
|
||||
'street_address' => $data->street_address,
|
||||
'zipcode' => $data->zipcode,
|
||||
'region' => 'ag',
|
||||
'is_default' => false,
|
||||
'channel_id' => $data->channel_id,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
44
database/seeders/LegalPageTableSeeder.php
Normal file
44
database/seeders/LegalPageTableSeeder.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Legal\LegalPage;
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LegalPageTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/legals.json'));
|
||||
|
||||
$table = 'legal_pages';
|
||||
DB::table($table)->truncate();
|
||||
|
||||
try {
|
||||
foreach ($datas as $data) {
|
||||
LegalPage::create([
|
||||
'slug' => $data->slug,
|
||||
'title' => translatable($data->title),
|
||||
'content' => $data->content ? translatable($data->content) : null,
|
||||
'is_active' => $data->is_enabled,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
42
database/seeders/MediaTableSeeder.php
Normal file
42
database/seeders/MediaTableSeeder.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MediaTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed the old data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$table = 'media';
|
||||
DB::table($table)->delete();
|
||||
|
||||
$datas = collect(json_decode(File::get('database/data/media.json')));
|
||||
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert((array) $data);
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore media error', $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
38
database/seeders/ModelHasRolesTableSeeder.php
Normal file
38
database/seeders/ModelHasRolesTableSeeder.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ModelHasRolesTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$table = 'model_has_roles';
|
||||
DB::table($table)->delete();
|
||||
|
||||
$datas = collect(json_decode(File::get('database/data/model_has_roles.json')));
|
||||
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert((array) $data);
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore model_has_roles error', $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
database/seeders/NewsletterTableSeeder.php
Normal file
34
database/seeders/NewsletterTableSeeder.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class NewsletterTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/newsletter_users.json'));
|
||||
|
||||
foreach ($datas as $data) {
|
||||
DB::table('newsletter_users')->insert([
|
||||
'email' => $data->email,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
118
database/seeders/OrderTableSeeder.php
Normal file
118
database/seeders/OrderTableSeeder.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OrderTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$orders = json_decode(File::get('database/data/orders.json'));
|
||||
$order_items = json_decode(File::get('database/data/order_items.json'));
|
||||
|
||||
$orders_table = 'orders';
|
||||
$order_items_table = 'order_items';
|
||||
|
||||
DB::table($orders_table)->truncate();
|
||||
DB::table($order_items_table)->truncate();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
try {
|
||||
DB::table($orders_table)->insert([
|
||||
'id' => $order->id,
|
||||
'number' => $order->number,
|
||||
'status' => $order->status,
|
||||
'shipping_method' => $order->shipping_method === 'on_own' ? 'self_pickup' : $order->shipping_method,
|
||||
'notes' => $order->notes,
|
||||
'customer_name' => $order->name,
|
||||
'customer_phone' => $order->phone,
|
||||
'customer_address' => $order->address,
|
||||
'delivery_time' => $this->getTime($order->time),
|
||||
'delivery_at' => $this->getDeliveryAt($order->time),
|
||||
'region' => $order->region,
|
||||
'province_id' => $order->province_id,
|
||||
'created_at' => $order->created_at,
|
||||
'updated_at' => $order->updated_at,
|
||||
'payment_type_id' => $this->getPaymentMethod($order->payment_type),
|
||||
'deleted_at' => $order->deleted_at,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($order_items as $orderItem) {
|
||||
try {
|
||||
DB::table($order_items_table)->insert([
|
||||
'id' => $orderItem->id,
|
||||
'product_name' => $orderItem->name,
|
||||
'product_id' => $orderItem->product_id,
|
||||
'order_id' => $orderItem->order_id,
|
||||
'channel_id' => $orderItem->channel_id,
|
||||
'quantity' => $orderItem->quantity,
|
||||
'unit_price_amount' => $orderItem->unit_price_amount,
|
||||
'created_at' => $orderItem->created_at,
|
||||
'updated_at' => $orderItem->updated_at,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$orders_table}_id_seq', (SELECT MAX(id) from {$orders_table}))
|
||||
");
|
||||
DB::statement("
|
||||
SELECT setval('{$order_items_table}_id_seq', (SELECT MAX(id) from {$order_items_table}))
|
||||
");
|
||||
}
|
||||
|
||||
public function getTime($data)
|
||||
{
|
||||
if (! $data) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$orderDelivery = explode(', ', $data);
|
||||
if (count($orderDelivery) < 2) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $orderDelivery[0];
|
||||
}
|
||||
|
||||
public function getDeliveryAt($data)
|
||||
{
|
||||
if (! $data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$orderDelivery = explode(', ', $data);
|
||||
if (count($orderDelivery) < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (new Carbon($orderDelivery[1]))->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payment id for method
|
||||
*/
|
||||
public function getPaymentMethod($method): int
|
||||
{
|
||||
return match ($method) {
|
||||
'cash' => 1,
|
||||
'atm' => 2,
|
||||
'online' => 3,
|
||||
default => 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
42
database/seeders/PaymentTypeTableSeeder.php
Normal file
42
database/seeders/PaymentTypeTableSeeder.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\System\Settings\Payments\PaymentType;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class PaymentTypeTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
collect([
|
||||
[
|
||||
'id' => 1,
|
||||
'code' => 'cash',
|
||||
'name' => ['en' => 'Cash', 'tk' => 'Nagt', 'ru' => 'Näliçni'],
|
||||
'tax' => 0,
|
||||
'is_enabled' => true,
|
||||
'options' => null,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'code' => 'atm',
|
||||
'name' => ['en' => 'ATM', 'tk' => 'Terminal', 'ru' => 'ATM'],
|
||||
'tax' => 0,
|
||||
'is_enabled' => true,
|
||||
'options' => null,
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'code' => 'online_halkbank',
|
||||
'name' => ['en' => 'Online (halkbank)', 'tk' => 'Onlaýn (halkbank)', 'ru' => 'Onlaýn (halkbank)'],
|
||||
'tax' => 0,
|
||||
'is_enabled' => true,
|
||||
'options' => null,
|
||||
],
|
||||
])->each(fn ($data) => PaymentType::create($data));
|
||||
}
|
||||
}
|
||||
42
database/seeders/PostBranchTableSeeder.php
Normal file
42
database/seeders/PostBranchTableSeeder.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PostBranchTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/post_branches.json'));
|
||||
|
||||
$table = 'post_branches';
|
||||
DB::table($table)->truncate();
|
||||
|
||||
try {
|
||||
foreach ($datas as $data) {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'province_id' => $data->province_id,
|
||||
'name' => $data->name,
|
||||
'address' => $data->address,
|
||||
'description' => $data->description,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
45
database/seeders/ProductHasRelationsTable.php
Normal file
45
database/seeders/ProductHasRelationsTable.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProductHasRelationsTable extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/product_has_relations.json'));
|
||||
|
||||
$table = 'product_has_relations';
|
||||
|
||||
try {
|
||||
foreach ($datas as $data) {
|
||||
DB::table($table)->insert([
|
||||
'product_id' => $data->product_id,
|
||||
'productable_type' => $this->getProductableType($data->productable_type),
|
||||
'productable_id' => $data->productable_id,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get productable type
|
||||
*/
|
||||
public function getProductableType(string $name): string
|
||||
{
|
||||
return match ($name) {
|
||||
'collection' => 'collection',
|
||||
'App\\Models\\Shop\\Channel' => 'channel',
|
||||
'category' => 'category',
|
||||
};
|
||||
}
|
||||
}
|
||||
74
database/seeders/ProductTableSeeder.php
Normal file
74
database/seeders/ProductTableSeeder.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProductTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$table = 'products';
|
||||
DB::table($table)->delete();
|
||||
|
||||
$datas = collect(json_decode(File::get('database/data/products.json')));
|
||||
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'parent_id' => $data->parent_id,
|
||||
'brand_id' => $data->brand_id,
|
||||
'name' => $data->name,
|
||||
'slug' => $data->slug,
|
||||
'description' => $data->description,
|
||||
'sku' => $data->sku,
|
||||
'barcode' => $data->barcode,
|
||||
'stock' => json_decode($data->options)?->quantity,
|
||||
'security_stock' => $data->security_stock,
|
||||
'old_price_amount' => $data->old_price_amount,
|
||||
'price_amount' => $data->price_amount,
|
||||
'cost_amount' => $data->cost_amount,
|
||||
'seo_title' => $data->seo_title,
|
||||
'seo_description' => $data->seo_description,
|
||||
'options' => json_encode([
|
||||
'back_order' => $data->backorder,
|
||||
'height_unit' => $data->height_unit,
|
||||
'height_value' => $data->height_value,
|
||||
'depth_unit' => $data->depth_unit,
|
||||
'depth_value' => $data->depth_value,
|
||||
'weight_value' => $data->weight_value,
|
||||
'width_unit' => $data->width_unit,
|
||||
'weight_unit' => $data->weight_unit,
|
||||
'width_value' => $data->width_value,
|
||||
'volume_value' => $data->volume_value,
|
||||
'volume_unit' => $data->volume_unit,
|
||||
]),
|
||||
'is_visible' => $data->is_visible,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['Ignore error', $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
38
database/seeders/ProvinceTableSeeder.php
Normal file
38
database/seeders/ProvinceTableSeeder.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProvinceTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/provinces.json'));
|
||||
|
||||
$table = 'provinces';
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'region' => $data->region,
|
||||
'name' => $data->name,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['province db erorr: ' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
51
database/seeders/ReviewTableSeeder.php
Normal file
51
database/seeders/ReviewTableSeeder.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ReviewTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/reviews.json'));
|
||||
|
||||
$table = 'reviews';
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'rating' => $data->rating,
|
||||
'title' => $data->title,
|
||||
'content' => $data->content,
|
||||
'product_id' => $data->reviewrateable_id,
|
||||
'user_id' => $data->author_id,
|
||||
'is_visible' => $data->approved,
|
||||
'is_recommended' => $data->is_recommended,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['reviews error: ' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
43
database/seeders/RolesTableSeeder.php
Normal file
43
database/seeders/RolesTableSeeder.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RolesTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/roles.json'));
|
||||
|
||||
$table = 'roles';
|
||||
foreach ($datas as $data) {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'name' => $data->name,
|
||||
'guard_name' => $data->guard_name,
|
||||
'display_name' => json_decode($data->display_name),
|
||||
'description' => json_decode($data->description),
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
24
database/seeders/SettingsSeeder.php
Normal file
24
database/seeders/SettingsSeeder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\System\Settings\Settings;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SettingsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
collect([
|
||||
[
|
||||
'key' => config('sms.database.key'),
|
||||
'value' => config('sms.database.value'),
|
||||
'display_name' => translatable('SMS API'),
|
||||
'locked' => false,
|
||||
],
|
||||
])->each(fn ($setting) => Settings::create($setting));
|
||||
}
|
||||
}
|
||||
78
database/seeders/UserTableSeeder.php
Normal file
78
database/seeders/UserTableSeeder.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UserTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starter kit data
|
||||
*/
|
||||
public function seedStarterKit(): void
|
||||
{
|
||||
collect([
|
||||
[
|
||||
'first_name' => 'Nurmuhammet',
|
||||
'last_name' => 'Allanov',
|
||||
'email' => 'nurmuhammet@mail.com',
|
||||
'password' => bcrypt('payload10'),
|
||||
],
|
||||
])->each(function ($data) {
|
||||
$user = User::create($data);
|
||||
|
||||
$user->assignRole('admin');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed old postshop data
|
||||
*/
|
||||
public function seedOldData(): void
|
||||
{
|
||||
User::truncate();
|
||||
|
||||
$users = json_decode(File::get('database/data/users.json'));
|
||||
|
||||
$table = 'users';
|
||||
foreach ($users as $user) {
|
||||
if ($user->deleted_at) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $user->id,
|
||||
'first_name' => $user->first_name,
|
||||
'last_name' => $user->last_name,
|
||||
'email' => $user->email,
|
||||
'phone_number' => $user->phone_number,
|
||||
'email_verified_at' => $user->email_verified_at,
|
||||
'password' => $user->password ?: bcrypt('gizlin'),
|
||||
'verified' => $user->verified_by_admin,
|
||||
'remember_token' => $user->remember_token,
|
||||
'created_at' => $user->created_at,
|
||||
'updated_at' => $user->updated_at,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['users error: ' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user