Dasun
Dasun

Reputation: 612

Laravel 5 Route Error

I`m new to laravel 5.4 so that i need to call these 2 functions in one view. here is the 2 controllers.

 public function index()
{
   $items = trainingprogramedetails::all()->last();
     return view('programesession/index',compact('items'));

}

 public function list()
{
   $lists = trainingprogramedetails::all();
     return view('programesession/index',compact('lists'));

}

Here is my view index.blade.php

<thead>
      <th>Name</th>
      <th>Data</th>
          </thead>

          <tbody>
              <tr>
                <td>Date</td>
                <td>{{ $items->date_of_programe }}</td>
              </tr>

              <tr>
                <td>Time</td>
                <td>{{ $items->time }}</td>
              </tr>

              <tr>
                <td>Venue</td>
                <td>{{ $items->venue }}</td>
              </tr>
          </tbody>
         </table> 

             <table class="table table-striped">
              <thead>

                <th>Trainee Programe ID</th>
                <th>Presenter Name</th>
                <th>Division</th>
                <th>Date</th>
              </thead>

              <tbody>
              @foreach($lists as $item)

                 <tr>

              <td>{{ $item->training_programe_id }}</td>
              <td>{{ $item->presenter_name }}</td>
              <td>{{ $item->division }}</td>
              <td>{{ $item->date }}</td>
          </tr>
                @endforeach

              </tbody>
      </table> 

So that this the error getting here. enter image description here

Here is my Rout

Route::group(['middleware' => ['web']], function () {
Route::resource('/programelist', 'TrainingProgrameSeassion');

});

Can you please help met to solve this?

Upvotes: 0

Views: 210

Answers (4)

Gowthaman D
Gowthaman D

Reputation: 579

You Should Use Like this proper code

    public function index()
{
   $items = trainingprogramedetails::all()->last();

return view('programesession.index')->with(compact('items'));

}

 public function list()
{
   $lists = trainingprogramedetails::all();

return view('programesession.index')->with(compact('lists'));

}

Upvotes: 0

Pete
Pete

Reputation: 312

Any reason not to combine the two functions? The other solution should handle the current error. If you do need two functions, it may be best to use partials as well

public function index()
{
   $items = trainingprogramedetails::all()->last();
   $lists = trainingprogramedetails::all();
   return view('programesession/index',compact('lists','items'));
}

Upvotes: 0

PaladiN
PaladiN

Reputation: 4944

As stated in the question, i came to know that you are you might be calling the index() function and not the list() function when calling the index route.

The question is not much clear and needs further clarification.

You need to use both variable in single function to achieve the solution.

public function index()
{
    $items = trainingprogramedetails::all()->last();
    $lists = trainingprogramedetails::all();

    return view('programesession/index', compact('items', 'lists'));
}

The error is caused because you either call the index method or the list method and not both and pass only items variables in the view and the lists variable in not there.

If the answer is not what you want then please add further codes and elaborate your question.

Upvotes: 0

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

I think you need update your view like:

@if(isset($items))
<table>
<thead>
     <th>Name</th>
     <th>Data</th>
         </thead>

         <tbody>
             <tr>
               <td>Date</td>
               <td>{{ $items->date_of_programe }}</td>
             </tr>

             <tr>
               <td>Time</td>
               <td>{{ $items->time }}</td>
             </tr>

             <tr>
               <td>Venue</td>
               <td>{{ $items->venue }}</td>
             </tr>
         </tbody>
        </table>
@endif

@if(isset($lists))
            <table class="table table-striped">
             <thead>

               <th>Trainee Programe ID</th>
               <th>Presenter Name</th>
               <th>Division</th>
               <th>Date</th>
             </thead>

             <tbody>
             @foreach($lists as $item)

                <tr>

             <td>{{ $item->training_programe_id }}</td>
             <td>{{ $item->presenter_name }}</td>
             <td>{{ $item->division }}</td>
             <td>{{ $item->date }}</td>
         </tr>
               @endforeach

             </tbody>
     </table>
@endif

Hope this work for you.

Upvotes: 1

Related Questions