php - Displaying categories from database in Laravel -


i have in category model

class categories extends eloquent {     protected $table = 'categories';     protected $primarykey = 'category_id';      public $timestamps = false; } 

then in homecontroller

public function index() {          $products = product::paginate(15);         return view::make('site.index', [             'products' => $products         ]);         } 

this working , showing products on page. have added function index()

        $categories = categories::paginate(15);         return view::make('site.index', [             'categories' => $categories         ]); 

and in index.blade.php

@foreach($categories $category)      {{{ $category['category_name'] }}} @endforeach 

and got blank page error

production.error: exception 'errorexception' message 'undefined variable: categories' in... 

what problem here , why can't list categories database?

in index method you've return view, no more code executed after return statement.
should this

public function index() {      $products = product::paginate(15);     $categories = categories::paginate(15);     return view::make('site.index', [         'products' => $products,         'categories' => $categories,     ]);          // or shorter     // return view('site.index', compact('products', 'categories'); }