Service Providers

App Service Provider

The following are customizations from the default app service provider

Default String Length

Set the database varchar data types to be 191 chars by default.


Force SSL

When the environment is not on local force SSL.

    if (config('app.env') !== 'local') {

Record sent emails

When an email is sent the following events first to save a copy of the email into a database. The sent emails can be seen in the settings menu.


Cache settings

System settings are saved in a settings table to reduce database lookups they are cached, if the cache exists the settings will be read otherwise they are looked up from the database.

If a setting matches a config name they the settings will override the config value.

    //if key exists
    if (Cache::has('setting_keys')) {
        //decode keys to array
        $keys = json_decode(Cache::get('setting_keys'), true);
        //loop over keys
        foreach ($keys as $key) {
            //override config setting
            config()->set([$key => Cache::get($key)]);
    } else {
        if (!Cache::has('setting_keys') && Schema::hasTable('settings')) { //if cache key does not exist
            //get all rows
            $settings = Setting::all();

            $keys = [];

            //loop over rows
            foreach ($settings as $setting) {
                $key    = $setting->key;
                $value  = $setting->value;
                $keys[] = $key;

                //remember setting
                Cache::forever($key, $value);

                //override config setting
                config()->set([$key => $value]);

            if (count($keys) > 0) {
                $keys = json_encode($keys);

                //create cache key remember forever
                Cache::forever('setting_keys', $keys);

Route Service Provider

The one change from a default laravel install is to change HOME constant to /admin

    public const HOME = '/admin';

© 2022 AdminTW. All rights reserved.

Built by David Carr