У меня есть таблица как эта таблица Activites:
![enter image description here](https://i.stack.imgur.com/bKvue.png)
и я извлекаю данные из базы данных в таблицу с этим кодом
в контроллере:
$TableB1 = \DB::table('users')
->join('group_user', 'users.id', '=', 'group_user.user_id')
->join('groups', 'groups.id', '=', 'group_user.group_id')
->select(
'users.name as name',
'group_user.user_id as id',
'groups.name as groupname'
)
->get();
$view->with('TableB1',$TableB1);
return $view;
In index.blade.php
<thead>
<tr>
<th>Team</th>
<th>Name</th>
<th>No. of Showing</th>
<th>No. of Follow up</th>
<th>New Lead</th>
<th>Personal Lead</th>
</tr>
</thead>
<tbody>
<?php
use Carbon\Carbon;
foreach ($TableB1 as $data){
echo
'<tr>
<th scope="row">'. $data->groupname .'</th>
<th scope="row">'. $data->name .'</th>';
// To extract the number of meetings done by each agent(owned_by_id) everyday
$meetings = \DB::table('meetings')
->where('company_id', 1)->where('owned_by_id', $data->id)
->where(DB::raw('DAY(created_at)'), Carbon::today()->day);
echo '<th scope="row">' . $meetings->count() . '</th>';
// To extract the number of calls done by each agent(owned_by_id) everyday
$calls = \DB::table('calls')
->where('company_id', 1)->where('owned_by_id', $data->id)
->where(DB::raw('DAY(created_at)'), Carbon::today()->day);
echo '<th scope="row">' . $calls->count() . '</th>';
// To extract the number of leads created by each agent(owned_by_id) everyday
$leads = \DB::table('leads')
->where('lead_status_id', 1)->where('company_id', 1)->where('owned_by_id', $data->id)
->where(DB::raw('DAY(created_at)'), Carbon::today()->day);
echo '<th scope="row">' . $leads->count() . '</th>';
}
?>
</tr>
</tbody>
Как переместить код в php blade на контроллер?
код работает, но я думаю, что код должен быть в контроллере правильно?
и, если возможно, есть ли способ отфильтровать эти данные в таблице по месяцам и годам через AJAX, чтобы мне не пришлось обновлять страницу?
Я использую Laravel 5.7