Skip to content

Instantly share code, notes, and snippets.

@nutch31
Created June 18, 2019 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nutch31/89d305b0fd1a260baed45cb608d20e10 to your computer and use it in GitHub Desktop.
Save nutch31/89d305b0fd1a260baed45cb608d20e10 to your computer and use it in GitHub Desktop.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Http\Request;
use Carbon\Carbon;
use DateTime;
use App\Model\Call;
use App\Model\Lead;
class updateDirectChannelIdCallLeads extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:updateDirectChannelIdCallLeads';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update Direct Channel Id in table leads field phone';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$leads = Lead::where('type', 'phone')
->whereNull('direct_channel_id')
->orderBy('submitted_date_time', 'asc')
->get();
foreach($leads as $lead)
{
$call = Call::where([
['date', $lead->submitted_date_time],
])->orderBy('date', 'desc')->first();
if(!empty($call))
{
Lead::where('id', $lead->id)->update([
'direct_channel_id' => $call->channel_id
]);
}
}
return response(array(
'Status' => 'Success'
), '200');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment