2017-05-04 13 views
0

私はlaravel 5.4に新しいので、私はこれらの2つの関数を1つのビューで呼び出す必要があります。 ここに2つのコントローラがあります。これは、エラーがここにきているので、ここでLaravel 5 Route Error

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')); 

} 

<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> 

index.blade.php私の見解です。 enter image description here

は、ここに私の敗走である

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

});

これを解決するためにお手伝いできますか?私はあなたのようなあなたのビューを更新する必要があると思う

+0

を使用する必要がありますそして、なぜあなたはそれがルートの問題であると思いますか?あなたはエラーメッセージを読んだことがありますか? – Amarnasan

+0

私はlaravel.whateverの新しい場合は、これは私の学部のプロジェクトのためです私はlaravel.iを使用してそれを行う必要がありますそれはルートissue.if私はそれが質問としてそれを知っていない知っている – Dasun

答えて

0

質問に記載されているように、インデックスルートを呼び出すときにindex()関数を呼び出していて、list()関数を呼び出していない可能性があります。

質問はあまり明確ではなく、さらに明確にする必要があります。

ソリューションを実現するには、両方の変数を単一の関数で使用する必要があります。

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

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

あなたはインデックスメソッドまたはリストのメソッドを呼び出し、両方ではないではなく、そこにビューでのみitems変数とlists変数を渡すのいずれかのため、エラーが発生しています。

答えがあなたの希望でない場合は、さらにコードを追加して質問を詳しく記述してください。

+0

ありがとうございました正常に動作します。 – Dasun

+0

それがあなたを助けてくれてうれしいよ:) – PaladiN

1

@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 

はあなたのためにこの作品を願っています。

0

2つの機能を組み合わせない理由は何ですか?他の解決策は、現在のエラーを処理する必要があります。あなたは2つの機能を必要とした場合は、それは同様にパーシャルを使用するのが最善かもしれ

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

あなたはこの正しいコードのように

​​