/
home
/
corsairdevelopme
/
public_html
/
amplivo-console
/
app
/
Providers
/
Upload File
HOME
<?php namespace App\Providers; use App\Models\SmtpMailSetting; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Cookie; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Validator; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { // } /** * Bootstrap any application services. * * @return void */ public function boot() { Schema::defaultStringLength(191); // if ($this->app->environment() !== 'local') { // URL::forceScheme('https'); // } // Set SMTP configuration according to SMTP setting if (Schema::hasTable('smtp_mail_settings')) { $settings = Cache::remember('smtp_mail_settings', 120, function () { return SmtpMailSetting::pluck('value', 'key')->toArray(); }); // If the table is empty, fall back entirely to env if (empty($settings)) { $settings = [ 'MAIL_HOST' => env('MAIL_HOST'), 'MAIL_PORT' => env('MAIL_PORT'), 'MAIL_USERNAME' => env('MAIL_USERNAME'), 'MAIL_PASSWORD' => env('MAIL_PASSWORD'), 'MAIL_FROM_ADDRESS' => env('MAIL_FROM_ADDRESS'), 'MAIL_FROM_NAME' => env('MAIL_FROM_NAME'), 'MAIL_ENCRYPTION' => env('MAIL_ENCRYPTION'), ]; } Config::set('mail.mailers.smtp.host', $settings['MAIL_HOST'] ?? env('MAIL_HOST')); Config::set('mail.mailers.smtp.port', $settings['MAIL_PORT'] ?? env('MAIL_PORT')); Config::set('mail.mailers.smtp.username', $settings['MAIL_USERNAME'] ?? env('MAIL_USERNAME')); Config::set('mail.mailers.smtp.password', $settings['MAIL_PASSWORD'] ?? env('MAIL_PASSWORD')); Config::set('mail.from.address', $settings['MAIL_FROM_ADDRESS'] ?? env('MAIL_FROM_ADDRESS')); Config::set('mail.from.name', $settings['MAIL_FROM_NAME'] ?? env('MAIL_FROM_NAME')); Config::set('mail.mailers.smtp.encryption', $settings['MAIL_ENCRYPTION'] ?? env('MAIL_ENCRYPTION')); } // forget session on browser close if (session()->has('guest_mode')) { Config::set('session.expire_on_close', true); } // remember user on browser close if condition meets $remember = Cookie::get(Auth::getRecallerName()); if ($remember) { Config::set('session.expire_on_close', false); } else { Config::set('session.expire_on_close', true); } // Custom validation rule. Validator::extend('alpha_spaces', function ($attribute, $value) { // This will only accept alpha and spaces. return !preg_match('/[^a-zA-z ]/u', $value); }); Validator::extend('alpha_dash_spaces', function ($attribute, $value) { // This will only accept alpha and spaces. // If you want to accept hyphens use: /^[\pL\s-]+$/u. return !preg_match('/[^a-zA-z-_ ]/u', $value); }); Validator::extend('alpha_num_dash', function ($attribute, $value) { // This will only accept alpha and spaces. return !preg_match('/[^a-zA-z0-9-_ ]/u', $value); }); Validator::extend('alpha_num_dash_spaces', function ($attribute, $value) { // This will only accept alpha and spaces. return !preg_match('/[^a-zA-z0-9- ]/u', $value); }); Validator::extend('alpha_num_spaces', function ($attribute, $value) { // This will only accept alpha, numbers and spaces. return !preg_match('/[^a-zA-z0-9 ]/u', $value); }); Validator::extend('address_ctm', function ($attribute, $value) { // This will only accept letters, numbers, hyphens, spaces, full stops, forward slashes, backslashes, and commas. return !preg_match('/[^a-zA-Z0-9-,. ]/u', $value); }); Validator::extend('email_ctm', function ($attribute, $value) { // This will only accept alpha and spaces. return !preg_match('/[^\w@._+-]/u', $value); }); Validator::extend('username_ctm', function ($attribute, $value) { // This will only accept alpha and spaces, number. return !preg_match('/[^a-zA-z0-9]/u', $value); }); Validator::extend('password_ctm', function ($attribute, $value) { // * At least 8 characters // * 1 letter // * 1 number // * 1 special character return preg_match('/^(?=.*[a-zA-Z])(?=.*\d)(?=.*[!@#$%^&*()_+])(?=.{8,})/', $value); }); } }