我可以在路由中为 Laravel 5.2 中的单个 blade 引用两个函数吗?
Can I reference two functions in routes for a single blade in Laravel 5.2?
是否可以在我的视图路径中从我的控制器引用两个函数。这是我拥有的:
我的路线
Route::get('/list-of-staffs', ['as' => 'listofstaffs', 'uses' => 'User\MasterlistController@listofstaffsTable']);
Route::get('/list-of-staffs', ['as' => 'listofstaffs', 'uses' => 'User\MasterlistController@summaryOfstaffsTable']);
有正确的方法吗?
@Rodrane,这是我的代码:
控制器:
public 函数 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);
}
这是我的blade
{!! $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>
请在下面查看我的文件。
这很好用:
{!! $searchresults !!}
但这给了我错误 'Call to a member function count() on array'
{!! $staffCount !!}
你能帮我解决这个问题吗?
已经知道了。看起来我错过了一个代码
是否可以在我的视图路径中从我的控制器引用两个函数。这是我拥有的:
我的路线
Route::get('/list-of-staffs', ['as' => 'listofstaffs', 'uses' => 'User\MasterlistController@listofstaffsTable']);
Route::get('/list-of-staffs', ['as' => 'listofstaffs', 'uses' => 'User\MasterlistController@summaryOfstaffsTable']);
有正确的方法吗?
@Rodrane,这是我的代码:
控制器:
public 函数 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);
}
这是我的blade
{!! $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>
请在下面查看我的文件。 这很好用:
{!! $searchresults !!}
但这给了我错误 'Call to a member function count() on array'
{!! $staffCount !!}
你能帮我解决这个问题吗?
已经知道了。看起来我错过了一个代码