/**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     $qb = \GoProp\Models\User::orderBy('id', 'ASC');
     $qb->whereHas('roles', function ($query) {
         $query->where('slug', 'agent');
     });
     $agents = $qb->get();
     foreach ($agents as $idx => $agent) {
         $agent->username = time() + $idx;
         $agent->save();
         $agent->username = \GoProp\Facades\AgentHelper::formatAgentCode($idx + 1);
         $agent->save();
     }
 }
Esempio n. 2
0
 public function getNextAgentCode()
 {
     $prefix = 'agent';
     $qb = User::orderBy('username', 'DESC');
     $qb->whereHas('roles', function ($query) {
         $query->where('slug', 'agent');
     });
     $lastAgent = $qb->first();
     if (!$lastAgent) {
         $lastAgentNumber = 0;
     } else {
         $lastAgentNumber = intval(str_replace($prefix, '', $lastAgent->username));
     }
     return $this->formatAgentCode($lastAgentNumber + 1);
 }