api code global jain
This commit is contained in:
57
app/Console/Commands/memberIdGenerate.php
Normal file
57
app/Console/Commands/memberIdGenerate.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\SanghMember;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class memberIdGenerate extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'add:member-id';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Add member id to sangh member table';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$membersGroupedBySangh = SanghMember::orderBy('id')->get()->groupBy('sangh_id');
|
||||
|
||||
foreach ($membersGroupedBySangh as $sanghId => $members) {
|
||||
$counter = 1;
|
||||
|
||||
foreach ($members as $member) {
|
||||
$newMemberId = str_pad($counter, 4, '0', STR_PAD_LEFT);
|
||||
$member->update(['member_id' => $newMemberId]);
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->info('Member IDs added to columns successfully.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user