HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/inzigd.komma.pro/app/Providers/SettingServiceProvider.php
<?php


namespace App\Providers;


use App\Komma\Employees\Models\Employee;
use Illuminate\Support\ServiceProvider;

class SettingServiceProvider extends ServiceProvider
{

    /**
     * Bootstrap the application
     *
     * Populate the config settings with database/cache stored values
     *
     */
    public function boot(){

        $this->populateEmployees();

    }

    /**
     * Populate the employees to be used as config variables
     */
    private function populateEmployees(){

        // Check if we have the table for employee
        if(\Schema::hasTable('employees')){

            // Try to get it out of the cache
            if(\Cache::has('employees')) $employees = \Cache::get('employees');
            else{
                $employees = Employee::whereNotNull('code_name')
                    ->with('images')
                    ->get();


                $cachedEmployees = [];
                foreach ($employees as $employee){

                    $cachedEmployee = [
                        'id' => $employee->id,
                        'firstName' => $employee->first_name,
                        'lastName' => $employee->last_name,
                        'function' => $employee->function,
                        'phone' => [
                            'display' => $employee->phone_display,
                            'call' => $employee->phone_call,
                        ],
                        'email' => $employee->email,
                        'linkedin' => $employee->linkedin,
                    ];

                    if(isset($employee->images) && $employee->images->isNotEmpty()){

                        $cachedEmployee['image'] = [
                            'small' => $employee->images->first()->small_image_url,
                            'large' => $employee->images->first()->large_image_url,
                        ];

                    }

                    $cachedEmployees[$employee->code_name] = $cachedEmployee;
                }

                \Log::info('Stored employees settings in cache');
                \Cache::forever('employees', $cachedEmployees);
                $employees = $cachedEmployees;
            }

            foreach ($employees as $codeName => $employee){
                \Config::set('enum.contactPersons.'.$employee['id'], $codeName);
                \Config::set('site.contactPersons.'.$codeName, $employee);
            }
        }

    }

}