You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
1.8 KiB
86 lines
1.8 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use WM\Core\Models\Business;
|
|
use WM\Core\Models\User;
|
|
|
|
class UserChangeInformation extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'transport:user';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'transport users';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
private function firstNameLengthUpdate(User $user)
|
|
{
|
|
$fistName = $user->first_name;
|
|
|
|
$fistNameLength = strlen(utf8_decode($fistName));
|
|
|
|
$user->update([
|
|
'first_name_length' => $fistNameLength
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
|
|
$users = User::all();
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$business = Business::find($user->business_id);
|
|
|
|
if (!is_null($business)) {
|
|
|
|
if ($business->user_id == $user->id) {
|
|
|
|
$this->firstNameLengthUpdate($user);
|
|
$business->user()->attach($user->id, [
|
|
'responsibility' => $user->responsibility,
|
|
'is_owner' => 1
|
|
]);
|
|
$this->info("add and update user : $user->id");
|
|
|
|
} else {
|
|
|
|
$this->firstNameLengthUpdate($user);
|
|
$business->user()->attach($user->id, [
|
|
'responsibility' => $user->responsibility
|
|
]);
|
|
$this->info("add and update user : $user->id");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|