D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
lactobokashi.com
/
database
/
seeders
/
Filename :
PaymentGatewayTableSeederVersionTwo.php
back
Copy
<?php namespace Database\Seeders; use App\Enums\GatewayMode; use App\Enums\Activity; use App\Enums\InputType; use App\Models\GatewayOption; use App\Models\PaymentGateway; use Illuminate\Database\Seeder; class PaymentGatewayTableSeederVersionTwo extends Seeder { /** * Run the database seeds. * * @return void */ public array $gateways = [ [ "name" => "Iyzico", "slug" => "iyzico", "misc" => null, "status" => Activity::DISABLE, "options" => [ [ "option" => 'iyzico_api_key', "type" => InputType::TEXT, "activities" => '' ], [ "option" => 'iyzico_secret_key', "type" => InputType::TEXT, "activities" => '' ], [ "option" => 'iyzico_mode', "type" => InputType::SELECT, "activities" => [ GatewayMode::SANDBOX => 'sandbox', GatewayMode::LIVE => 'live' ] ], [ "option" => 'iyzico_status', "value" => Activity::DISABLE, "type" => InputType::SELECT, "activities" => [ Activity::ENABLE => "enable", Activity::DISABLE => "disable", ] ], ] ], [ "name" => "Telr", "slug" => "telr", "misc" => null, "status" => Activity::DISABLE, "options" => [ [ "option" => 'telr_store_id', "type" => InputType::TEXT, "activities" => '' ], [ "option" => 'telr_store_auth_key', "type" => InputType::TEXT, "activities" => '' ], [ "option" => 'telr_mode', "type" => InputType::SELECT, "activities" => [ GatewayMode::SANDBOX => 'sandbox', GatewayMode::LIVE => 'live' ] ], [ "option" => 'telr_status', "value" => Activity::DISABLE, "type" => InputType::SELECT, "activities" => [ Activity::ENABLE => "enable", Activity::DISABLE => "disable", ] ], ] ], ]; public function run(): void { foreach ($this->gateways as $gateway) { $payment = PaymentGateway::create([ 'name' => $gateway['name'], 'slug' => $gateway['slug'], 'misc' => json_encode($gateway['misc']), 'status' => $gateway['status'] ]); if (file_exists(public_path('/images/seeder/payment-gateway/' . strtolower(str_replace(' ', '_', $gateway['slug'])) . '.png'))) { $payment->addMedia(public_path('/images/seeder/payment-gateway/' . strtolower(str_replace(' ', '_', $gateway['slug'])) . '.png'))->preservingOriginal()->toMediaCollection('payment-gateway'); } $this->gatewayOption($payment->id, $gateway['options']); } } public function gatewayOption($id, $options): void { if (!blank($options)) { foreach ($options as $option) { GatewayOption::create([ 'model_id' => $id, 'model_type' => PaymentGateway::class, 'option' => $option['option'], 'value' => $option['value'] ?? "", 'type' => $option['type'], 'activities' => json_encode($option['activities']), ]); } } } }