Могу ли я ссылаться на две функции в маршрутах для одного блейда в 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, вот мои коды:

Контроллер:
общедоступная функция 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 !!}

Не могли бы вы помочь мне в этом?


person Rodney Zanoria    schedule 08.05.2017    source источник
comment
могу я спросить, зачем ты это делаешь?   -  person Anar Bayramov    schedule 08.05.2017
comment
@Rodrane Конечно, на самом деле мне трудно использовать более одной переменной в одном лезвии, поэтому я подумал о создании другого лезвия или представления. Я знаю, что это глупо. Возможно ты можешь помочь мне. Позвольте мне опубликовать мои коды выше   -  person Rodney Zanoria    schedule 08.05.2017
comment
@Rodrane Я обновил пост выше   -  person Rodney Zanoria    schedule 08.05.2017
comment
у вас нет проблем с передачей данных, я думаю, у вас нет правильных данных, возможно, что-то в этой строке $count = $staffs->count();   -  person Anar Bayramov    schedule 08.05.2017


Ответы (1)


Получил это уже. Похоже на код, который я пропустил

person Rodney Zanoria    schedule 11.05.2017
comment
Я настоятельно рекомендую вам уточнить, какой код вы пропустили и что вы сделали для решения своей проблемы. В противном случае этот ответ не очень полезен для будущих читателей этого поста. Спасибо. - person Pang; 11.05.2017