LinkStack/app/Providers/AppServiceProvider.php
Julian Prieber 1950ba2a18 Now forcing usernames to be unique
Now forcing usernames to be unique in regard to capitalization.
2023-01-23 16:06:07 +01:00

42 lines
952 B
PHP
Executable File

<?php
namespace App\Providers;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\DB;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Paginator::useBootstrap();
Validator::extend('isunique', function ($attribute, $value, $parameters, $validator) {
$value = strtolower($value);
$query = DB::table($parameters[0])->whereRaw("LOWER({$attribute}) = ?", [$value]);
if (isset($parameters[1])) {
$query->where($parameters[1], '!=', $parameters[2]);
}
return $query->count() === 0;
});
}
}