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

时间:2015-03-31 12:52:48

标签: php laravel-5

UrlGenerator.php第252行中的ErrorException:

  

路线[类别]未定义。 (查看: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 个答案:

答案 0 :(得分:0)

URL::route()route()期望路线名称作为第一个参数。您的路线目前没有名称,请通过添加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))
相关问题