Merge pull request #12684 from snipe/features/added_console_command_to_normalize_names
Added console command to normalize capitalization on names
This commit is contained in:
commit
ffb87a0a87
1 changed files with 52 additions and 0 deletions
52
app/Console/Commands/NormalizeUserNames.php
Normal file
52
app/Console/Commands/NormalizeUserNames.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class NormalizeUserNames extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'snipeit:normalize-names';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Normalizes weirdly formatted names as first-letter upercased';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
$users = User::get();
|
||||||
|
$this->info($users->count() . ' users');
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$user->first_name = ucwords(strtolower($user->first_name));
|
||||||
|
$user->last_name = ucwords(strtolower($user->last_name));
|
||||||
|
$user->email = strtolower($user->email);
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue