2015-03-31 37 views
0

ErrorException在UrlGenerator.php线252:传递变量(途径[类别]没有定义)

路线[类别]未被定义。 (查看:d:\ XAMPP \ htdocs中\ laravel \资源\意见\网页\ 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}', '[email protected]'); 

回答

0

URL::route()route()预计路线名称作为第一个参数。您的路线目前还没有名字,更改通过添加as

Route::get('category/{category_id}', [ 
    'as' => 'category', 
    'uses' => '[email protected]' 
]); 

或者您可以使用URL::action()action()通过它来获取路由的控制器动作:

URL::action('[email protected]', array('category_id' => $product_category_values->tbl_product_category_id))