2021-06-05 09:26:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2022-01-14 12:27:21 +00:00
|
|
|
use App\Models\Settings;
|
2021-06-05 09:26:32 +00:00
|
|
|
use Illuminate\Pagination\Paginator;
|
2022-01-19 22:31:24 +00:00
|
|
|
use Illuminate\Support\Facades\App;
|
2021-06-05 09:26:32 +00:00
|
|
|
use Illuminate\Support\Facades\Schema;
|
2021-07-28 16:22:12 +00:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2021-06-05 09:26:32 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2022-01-14 12:27:21 +00:00
|
|
|
|
2021-06-05 09:26:32 +00:00
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
|
|
|
Paginator::useBootstrap();
|
|
|
|
Schema::defaultStringLength(191);
|
2021-07-28 16:22:12 +00:00
|
|
|
|
|
|
|
Validator::extend('multiple_date_format', function ($attribute, $value, $parameters, $validator) {
|
|
|
|
$ok = true;
|
|
|
|
$result = [];
|
|
|
|
|
|
|
|
// iterate through all formats
|
|
|
|
foreach ($parameters as $parameter) {
|
|
|
|
//validate with laravels standard date format validation
|
|
|
|
$result[] = $validator->validateDateFormat($attribute, $value, [$parameter]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//if none of result array is true. it sets ok to false
|
|
|
|
if (!in_array(true, $result)) {
|
|
|
|
$ok = false;
|
|
|
|
$validator->setCustomMessages(['multiple_date_format' => 'The format must be one of ' . join(",", $parameters)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ok;
|
|
|
|
});
|
2022-01-14 12:27:21 +00:00
|
|
|
|
2022-01-19 22:31:24 +00:00
|
|
|
if (!App::runningInConsole()) {
|
|
|
|
// Set Discord-API Config
|
|
|
|
config(['services.discord.client_id' => Settings::getValueByKey('SETTINGS::DISCORD:CLIENT_ID')]);
|
|
|
|
config(['services.discord.client_secret' => Settings::getValueByKey('SETTINGS::DISCORD:CLIENT_SECRET')]);
|
2022-01-14 12:27:21 +00:00
|
|
|
|
2022-01-19 22:31:24 +00:00
|
|
|
// Set Recaptcha API Config
|
|
|
|
config(['recaptcha.api_site_key' => Settings::getValueByKey('SETTINGS::RECAPTCHA:SITE_KEY')]);
|
|
|
|
config(['recaptcha.api_secret_key' => Settings::getValueByKey('SETTINGS::RECAPTCHA:SECRET_KEY')]);
|
2022-01-14 12:34:37 +00:00
|
|
|
|
2022-01-19 22:31:24 +00:00
|
|
|
// Set all configs from database
|
|
|
|
$settings = Settings::all();
|
|
|
|
foreach ($settings as $setting) {
|
|
|
|
config([$setting->key => $setting->value]);
|
|
|
|
}
|
2022-01-14 12:34:37 +00:00
|
|
|
}
|
2021-06-05 09:26:32 +00:00
|
|
|
}
|
|
|
|
}
|