I'm trying to get a count of model rows from a different database. I have both databases configured fine. My problem is that it doesn't seem to be using the same connection when attempting to perform raw queries.
Code:
class Lead extends Model
{
protected $connection = 'infused2';
public $timestamps = false;
function campaignCount(Campaign $campaign)
{
$leads = $this->join('lead_history', 'leads.id', '=', 'lead_history.id_lead')->join('assignments', 'leads.id', '=', 'assignments.id_lead');
if (!empty($campaign->lead_date_created_operand)) {
if ($campaign->leadDateCreatedOperand->name == 'day age') {
$leads->where(DB::raw("date_format(from_unixtime(lead_history.date_created), '%d-%m-%Y') = date_format(".strtotime($campaign->lead_date_created_value).", '%d-%m-%Y')"));
}
else if ($campaign->leadDateCreatedOperand->name == 'month age') {
$leads->where(DB::raw("date_format(from_unixtime(lead_history.date_created), '%m-%Y') = date_format(".strtotime($campaign->lead_date_created_value).", '%m-%Y')"));
}
}
if (!empty($campaign->lead_date_assigned_operand)) {
if ($campaign->leadDateAssignedOperand->name == 'day age') {
$leads->where(DB::raw("date_format(from_unixtime(assignments.date_assigned), '%d-%m-%Y') = date_format(".strtotime($campaign->lead_date_assigned_value).", '%d-%m-%Y')"));
}
else if ($campaign->leadDateAssignedOperand->name == 'month age') {
$leads->where(DB::raw("date_format(from_unixtime(assignments.date_assigned), '%m-%Y') = date_format(".strtotime($campaign->lead_date_assigned_value).", '%m-%Y')"));
}
}
return $leads->count();
}
}
I am getting error Database [mysql] not configured
. Why is this happening and how do I make the raw queries use the model connection?