在 URL Laravel 5 中传递变量(路线 [类别] 未定义)

Pass variables in URL Laravel 5 (Route [category] not defined)

UrlGenerator.php 第 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');

URL::route()route() 期望路由 name 作为第一个参数。您的路线目前没有名称,请通过添加 as:

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

或者,您可以使用 URL::action()action() 通过其控制器操作获取路线:

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