Можно ли ссылаться на две функции из моего контроллера в моих маршрутах, идущих к моему представлению. Вот что у меня есть:
Мои маршруты
Route::get('/list-of-staffs', ['as' => 'listofstaffs', 'uses' => 'User\MasterlistController@listofstaffsTable']);
Route::get('/list -of-staffs', ['as' => 'listofstaffs', 'uses' => 'User\MasterlistController@summaryOfstaffsTable']);
Есть ли правильный способ сделать это?
@Rodrane, вот мои коды:
Контроллер:
общедоступная функция listofstaffsTable() {
$staffs = DB::table('staff_profiles')
->select('id','last_name','first_name','middle_name','name_ext','birthday','encoded_by')
->orderBy('last_name','ASC')
->get();
$count = $staffs->count();
$searchresults = ""; // define the searchresults variable
$i = 1;
foreach( $staffs as $key => $profile ) {
$category = GetCategory::show($profile->id);
$getcurrentklc = staffshipHistory::where('profile_id', '=', $profile->id)
->orderBy('effective_date', 'DESC')
->first(); // get the current klc from the most recent staffship history entry
if( $getcurrentklc == null )
{
$currentklc = "";
}
else
{
$currentklc = $getcurrentklc->congregation_name;
}
$getmemtype = staffshipHistory::where('profile_id', '=', $profile->id)
->orderBy('effective_date', 'DESC')
->first(); // get the current klc from the most recent staffship history entry
if( $getmemtype == null )
{
$memtype = "";
}
else
{
$memtype = $getmemtype->staffship_type;
}
$getdatebaptized = staffshipHistory::where('profile_id', '=', $profile->id)
->where('log_reason', '=', 'New staff')
->orderBy('effective_date', 'DESC')
->first(); // get the current klc from the most recent staffship history entry
if( $getdatebaptized == null )
{
$datebaptized = "";
}
else
{
$datebaptized = $getdatebaptized->effective_date;
}
$getmotherinspirit1 = staffshipHistory::where('profile_id', '=', $profile->id)
->where('log_reason', '=', 'New staff')
->orderBy('effective_date', 'DESC')
->first(); // get the current klc from the most recent staffship history entry
if( $getmotherinspirit1 == null )
{
$motherinspirit1 = "";
}
else
{
$motherinspirit1 = $getmotherinspirit1->mother_spirit_1_name;
}
$getmemstatus = staffshipHistory::where('profile_id', '=', $profile->id)
->orderBy('effective_date', 'DESC')
->first(); // get the current klc from the most recent staffship history entry
if( $getmemstatus == null )
{
$memstatus = "";
}
else
{
$memstatus = $getmemstatus->staffship_status;
}
$searchresults .= '<tr>'.
'<td>'. $i .'</td>'.
'<td><a href="'. URL::route('viewstaffprofile', $profile->id) .'">'. $profile->last_name .' '. $profile->first_name .' '. $profile->middle_name .' '. $profile->name_ext .' </a></td>'.
'<td>'. $currentklc .'</td>'.
'<td>'. $category .'</td>'.
'<td>'. $memtype .'</td>'.
'<td>'. $memstatus .'</td>'.
'<td>'. $datebaptized .'</td>'.
'<td>'. $motherinspirit1 .'</td>'.
'<td>'. $profile->encoded_by .'</td>'.
'</tr>';
$i++;
}
$data = [];
$data['searchresults'] = $searchresults;
$data['staffCount'] = $count;
return view( 'user/masterlist/list-of-staffs', $data);
}
это мой клинок
{!! $staffCount !!}
<hr>
<div class="page-header" style="text-align:center;">
<h3 class="pageHeader">
List of staffs
<br>
</h3>
</div>
<div class="row">
<table class="table table-bordered" style="text-align: left;">
<tr>
<th></th>
<th>Full Name (Last, First, Middle)</th>
<th>KLC</th>
<th>Category</th>
<th>Mem Type</th>
<th>Mem Status</th>
<th>Date Baptized</th>
<th>Mother in Spirit</th>
<th>Encoder</th>
</tr>
<tbody>
{!! $searchresults !!}
</tbody>
</table>
</div>
Пожалуйста, смотрите мои файлы ниже. Это отлично работает:
{!! $результаты поиска !!}
Но это дает мне ошибку "Вызов функции-члена count() в массиве"
{!! $staffCount !!}
Не могли бы вы помочь мне в этом?
$count = $staffs->count();
- person Anar Bayramov   schedule 08.05.2017