0
votes

ErrorException in UrlGenerator.php line 252:

Route [category] not defined. (View: D:\xampp\htdocs\laravel\resources\views\pages\home.blade.php)

Home.blade.php

$product_category = DB::table('tbl_products_category')
                                                ->select('tbl_product_category_id', 'tbl_product_category_name')
                                                ->where('tbl_product_category_status', '=', 1)
                                                ->get();
                                  ?>
                                  @foreach($product_category as $product_category_values)
                                  <li><a href="{{ URL::route('category', array('category_id' => $product_category_values->tbl_product_category_id)) }}"> {{ $product_category_values->tbl_product_category_name }}</a>
                                  </li>
                                  @endforeach

HomeController.php

 <?php namespace App\Http\Controllers;

    class HomeController extends Controller {

        public function index()
        {
           return view('pages.home');
        }

            public function getproductDetails($category_id)
            {
               return $category_id; 
               //return view('welcome'); 
            }        

    }

Route.php

Route::get('category/{category_id}', 'HomeController@getproductDetails');
1

1 Answers

0
votes

URL::route() or route() expect a route name as first argument. Your route currently has no name, change that by adding as:

Route::get('category/{category_id}', [
    'as' => 'category',
    'uses' => 'HomeController@getproductDetails'
]);

Alternatively you can use URL::action() or action() to fetch the route by it's controller action:

URL::action('HomeController@getproductDetails', array('category_id' => $product_category_values->tbl_product_category_id))