So I am currently working on a project where I have a table that shows an overview of managers and the number of applications they are assigned to that currently have a certain status. What I am trying to do is when the user clicks on a number (which is the count) it returns a list view that queries from the database ONLY those applications that are assigned to that manager and that status. Otherwise, if the user goes to the application view, it should show ALL applications.
Here is the code of the View for my overview:
<table class="table tablesorter" id="tblAffs">
<thead>
<tr class="tblhead">
<th>AM</th>
<th>Qualified Prospect</th>
<th>Unqualified Prospect</th>
<th>Contacted</th>
<th>Converted To Account</th>
<th>Pending Integration</th>
<th>Revenue Generating</th>
</tr>
</thead>
<tbody>
@foreach ($totalCount as $id => $name) {{-- id is the admin id --}}
@foreach($name as $n => $status) {{-- $n is the name, $status is array of the counts --}}
<tr>
<td>
{{$n}}
<br>
<a href="#">Closed</a>
</td>
<td><a href="/ap1/{{$new_lead}}/applications?status=2">{{ isset($status[2]) ? $status[2] : 0 }}</a></td>
<td><a href="/ap1/{{$new_lead}}/applications?status=1">{{ isset($status[1]) ? $status[1] : 0 }}</a></td>
<td><a href="/ap1/{{$new_lead}}/applications?status=3">{{ isset($status[3]) ? $status[3] : 0 }}</a></td>
<td><a href="/ap1/{{$new_lead}}/applications?status=4">{{ isset($status[4]) ? $status[4] : 0 }}</a></td>
<td><a href="/ap1/{{$new_lead}}/applications?status=5">{{ isset($status[5]) ? $status[5] : 0 }}</a></td>
<td><a href="/ap1/{{$new_lead}}/applications?status=6">{{ isset($status[6]) ? $status[6] : 0 }}</a></td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
On my controller for this overview this is the code and how data structure created:
public function overview()
{
$query= DB::table('admins')
->join('advertiser_applications', 'admins.id', '=', 'advertiser_applications.assigned_to')
->selectRaw('advertiser_applications.status, admins.id, admins.first_name, COUNT(advertiser_applications.status) count')
->groupBy('admins.id', 'advertiser_applications.status');
$counts = $query->get();
$totalCount = [];
foreach($counts as $count){
$totalCount[$count->id][$count->first_name][$count->status] = $count->count;
}
return View::make('admin.crm.overview', ['totalCount' => $totalCount, 'admin_id' => AuthAdmin::admin(false), 'tpl_title' => 'CRM Advertiser Overview', 'new_lead' => 'advertisers']);
}
Here is the code from my Controller for my view that brings up the list. This is where I am confused as to how I will pass in that status and id if that href is clicked.
public function index($param)
{
$query = AdvertiserApplication::with('admin');
$status = Input::get('status');
if (!empty($status) || $status === '0')
$query->where('status', '=', $status);
$applications = $query->get();
return View::make('admin.advertisers.application_list', ['applications' => $applications, 'admin_id' => AuthAdmin::admin(false)]);
}
Now I am not sure if that is the proper way to link that I have written in my href. Should I do a URL link to route or something like that? I am not sure yet. Any tips would be much appreciated!
With this your URL:
<a href="/ap1/{{$new_lead}}/applications?status=2">{{ isset($status[2]) ? $status[2] : 0 }}</a>
If you have
route::get('/ap1/{new_lead}', array('as' => 'page-name', 'uses' => 'yourController@functionName'));
in controller:
public function functionName($new_lead){
// use $new_lead here to get your data
}