2017-05-04 105 views
1

這是我需要履行的觀點。 enter image description hereLaravel 5查看屬性不存在錯誤

因此,我需要全表數據,並在其他細節需要填寫一次用戶填寫它。因此,這裏是index.blade.php

<table class="table table-bordered"> 
      <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($items 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> 

所以這裏的觀點是,我發現了錯誤。 enter image description here

所以這是我的控制器指數函數。

public function index() 
{ 
    $items = trainingprogramedetails::all(); 
    return view('programesession.index',compact('items')); 
} 
public function create() 
    { 
     return view('programesession.programes'); 
    } 

public function store(Request $request) 
    { 
     trainingprogramedetails::create($request->all()); 
       return view('programesession.programes'); 
    } 

這是我的創建視圖。

<div class="jumbotron"> 
      <div class="form-group"> 
      <label>Date</label> 
      <input class="form-control" name="date_of_programe" type="date" value="2011-08-19" id="example-date-input"> 
      </div> 

      <div class="form-group"> 

      <label>Time</label> 
      <input type="text" name="time" type="time" class="form-control" value=""> 
      </div> 

      <div class="form-group"> 

      <label>Venue</label> 
      <input type="text" name="venue" class="form-control" value=""> 
      </div> 

      <div class="form-group"> 
      <label>Training Programe Id</label> 
      <input type="text" name="training_programe_id" class="form-control" value="TR/PR/"> 
      </div> 

      <div class="form-group"> 
      <label>Presenter Name</label> 
      <input type="text" name="presenter_name" class="form-control" value=""> 
      </div> 

      <div class="form-group"> 
      <label>Division</label> 
      <input type="text" name="division" class="form-control" value=""> 
      </div> 

      <div class="form-group"> 
      <label>Date</label> 
      <input class="form-control" name="date" type="date" value="2011-08-19" id="example-date-input"> 
      </div> 

      <input type="submit" class="btn btn-success pull-right"> 

因此,誰能建議我來解決這個問題? 謝謝。

+0

嘛錯誤消息相當不言自明。你能告訴我們你的控制器中dd($ items)的結果嗎? – Mozammil

+0

'$ items'將與數組的集合,所以你不能沒有索引來訪問它,嘗試'$項目[0] - > date_of_programe' –

+0

先生嗯新的laravel可以請你說我什麼是DD($項目) – Dasun

回答

0

問題就在這裏:

<td>{{ $items->date_of_programe }}</td> 

$items是陣列的集合,所以要訪問它的屬性嘗試:

foreach($items as $item) 
{ 
    echo $item['date_of_programe']; 
} 

$items[0]->date_of_programe 
+0

爵士$項目[0] - > date_of_programe.works,但如果用戶添加新值表數據應添加爲新values.how我可以修改這個? – Dasun

+0

使用'的foreach()'的方式來代替,它適用於所有屬性 –

+0

它的工作原理,但在數據庫中的所有DATAS將被打印出來我now.how可以固定呢? – Dasun