0

I am new to laravel and want to populate my view using foreach . This is view:

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

Controller:

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:

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

I am trying from quite sometime but not getting through.A liitle help will be appreciated.Thanks in advance

8
  • Wrong syntax try this correct syntax Commented Jul 8, 2017 at 6:13
  • your trying to apply codigniter data send format in laravel Commented Jul 8, 2017 at 6:13
  • cant we do like what we do incodeigniter Commented Jul 8, 2017 at 6:15
  • no .laravel bit differ . data should be passed like i mentioned below . Commented Jul 8, 2017 at 6:19
  • thanks @JYoThI.I will try over this using foreach syntax in laravel Commented Jul 8, 2017 at 6:21

1 Answer 1

1

Data should be passed like this using compact() based on version it will little bit change read documentation here 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'));
  }
}

Note : your trying to apply codigniter data send format in laravel

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.