HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/work.naniguide.com/database/migrations/2023_03_17_045842_lead_custom_field.php
<?php

use App\Models\Company;
use App\Models\LeadCustomForm;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */

    public function up()
    {
        $companies = Company::get();

        foreach ($companies as $company) {
            $LeadCustomProductForm = LeadCustomForm::where('company_id', $company->id)->where('field_name', 'product')->first();

            if(is_null($LeadCustomProductForm)){
                LeadCustomForm::create([
                    'field_display_name' => 'Product',
                    'field_name' => 'product',
                    'field_order' => 8,
                    'field_type' => 'select',
                    'company_id' => $company->id,
                ]);
            }

            $LeadCustomSourceForm = LeadCustomForm::where('company_id', $company->id)->where('field_name', 'source')->first();

            if(is_null($LeadCustomSourceForm)){
                LeadCustomForm::create([
                    'field_display_name' => 'Source',
                    'field_name' => 'source',
                    'field_order' => 9,
                    'field_type' => 'select',
                    'company_id' => $company->id,
                ]);
            }
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */

    public function down()
    {
        //
    }

};