Laravel, passing new function to blade
I have a working class file, controller and view that show different samples of data, but I’m currently adding a new function which grabs data from the database, passing that to the controller and defining it, then passing it to the blade/view.
I’m not really doing anything differently than the other functions but the data is not showing in my blade. The placeholder is spaced appropriately on the webpage but the data doesn’t show up. The query is getting results and the function is passing to the blade because the foreach is creating additional rows. I’m thinking I’m using improper syntax for the variables in my blade which is why my data isn’t actually showing.
Any help appreciated here:
EMPLOYEE.php
class employeeCalls
{
public function __construct()
{
$this->yyyy = date('Y');
$this->pyyy = $this->yyyy - 1;
$this->from = "{$this->pyyy}-01-01";
$this->through = $this->pyyy . '-' . date('m-d');
$this->fullYear = "{$this->pyyy}-12-31";
$this->newFrom = "{$this->yyyy}-01-01";
$this->newThrough = date('Y-m-d');
}
public function sample($employee)
{
$employee = (int) $employee;
$from = $this->from;
$through = $this->through;
$newFrom = $this->newFrom;
$newThrough = $this->newThrough;
$FullYear = $this->fullYear;
$sql = "
select employee, 'PRIOR' as Range, count(*) as count
from empCalls
where employee = {$employee}
AND fordate between '{$from}' and '{$through}'
group by employee
union all
select employee, 'CURRENT' as Range, count(*) as count
from empCalls
where employee = {$employee}
AND fordate between '{$newFrom}' and '{$newThrough}'
group by employee
union ALL
select employee, 'FULL' as Range, count(*) as count
from empCalls
where employee = {$employee}
AND fordate between '{$from}' and '{$FullYear}'
group by employee
";
return Connection::runQuery($sql);
}
}
EmployeeController.php
$employeeCalls = new employeeCalls();
$samples = $employeeCalls->sample($this->slsno);
return view('Employee.index')
->with('slsno', $this->slsno)
->with('samples', $samples);
}
blade.php
<div class="md-card-content">
@foreach($samples as $sample)
<div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center"></span></div>
<span class="uk-text-muted uk-text-medium">2017 YTD</span>
<div class="clearfix"></div>
<div class="clearfix"></div>
<hr />
<div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center"></span></div>
<span class="uk-text-muted uk-text-medium">2018 YTD</span>
<div class="clearfix"></div>
<div class="clearfix"></div>
<hr />
<div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center"></span></div>
<span class="uk-text-muted uk-text-medium">2017 Full Year</span>
<div class="clearfix"></div>
<div class="clearfix"></div>
<hr />
@endforeach
</div>
UPDATE:
This is what dumps from $samples
array:3 [▼
0 => array:3 [▼
"employee" => "495"
"RANGE" => "PRIOR"
"COUNT" => "119"
]
1 => array:3 [▼
"employee" => "495"
"RANGE" => "CURRENT"
"COUNT" => "68"
]
2 => array:3 [▼
"employee" => "495"
"RANGE" => "FULL"
"COUNT" => "440"
]
]
from Laravel Questions and Answers https://laravelquestions.com/php/laravel-passing-new-function-to-blade/
via Lzo Media
No comments:
Post a Comment