feat: create command businesses and users change column data

BE.remove-column-business
Azizi 4 years ago
parent f00eeb3241
commit dd28b95f85

@ -0,0 +1,85 @@
<?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");
}
}
}
}
}
Loading…
Cancel
Save