2017-07-08 29 views
0

我是laravel的新手,想用foreach填充我的視圖。 這是視圖:laravel中沒有定義的foreach變量5.2

<thead> 
           <tr> 
            <th>Sr. No.</th> 
            <th>Name</th> 

            <th>Mobile No</th> 
            <th>Email ID</th> 
            <th>Address</th> 
            <th>Action</th> 
           </tr> 
          </thead> 
          <tbody> 
          <?php foreach($result as $res){?> 
           <tr> 
            <td>1</td> 
            <td><?php echo $res->vendor_name;?></td> 

            <td><?php echo $res->mobile;?></td> 
            <td><?php echo $res->email;?></td> 
            <td><?php echo $res->city;?></td> 
            <td> 
             <a href="#" data-toggle="modal" data-target=".Upcoming" class="btn btn-success btn-sm"><i class="fa fa-edit"></i></a> 
             <a href="#" class="btn btn-warning btn-sm"><i class="fa fa-trash"></i></a> 
            </td> 
           </tr> 
           <?php }?> 

控制器:

class VendorController extends Controller 
{ 
    public function getVendorList(){ 
     $vendors=DB::table('vendor_master')->get(); 
     $data['result']=$vendors; 
     $data['header'] = View::make('header')->render(); 
     $data['footer'] = View::make('footer')->render(); 
     return view('vendor_details', $data); 
    } 
} 

路線:

Route::controller('vendor','VendorController'); 

我從相當一段時間努力,但沒有得到through.A liitle幫助將是appreciated.Thanks advance

+0

語法錯誤試試這個[正確的語法(https://開頭laravel.com/docs/5.4/blade#loops) –

+0

你試圖在laravel中應用codigniter數據發送格式 – JYoThI

+0

我們不喜歡我們做incodeigniter –

回答

1

數據應該像這樣通過使用compact()基於版本會有點變化來讀取文檔在這裏laravel documenation

class VendorController extends Controller 
{ 
    public function getVendorList(){ 
     $vendors=DB::table('vendor_master')->get(); 
     $result=$vendors; 
     $header = View::make('header')->render(); 
     $footer = View::make('footer')->render(); 
     return view('vendor_details',compact('result','header','footer')); 
    } 
} 

注:你想申請codigniter數據laravel發送格式