2017-04-22 64 views
0

的UrlGenerator抛出一个异常Laravel授权抛出一个错误在刀片模板使用时

ErrorException in UrlGenerator.php line 337: 

Action App\Http\Controllers\[email protected] not defined. 

我在ProductPolicy

有这样的代码在我的刀片产品视图

@can('view', App\Product::class) 
    <a href="{{ action('[email protected]', 1) }}">Product View</a> 
@endcan 

所以我在AuthServiceProvider类中注册了产品策略

protected $policies = [ 
    Product::class => ProductPolicy::class 
]; 
+0

请出示你的'ProductController'和'web.php' –

+0

我使用的资源'路线::资源( '产品', 'ProductController的');' –

回答

0

传递给操作方法的第二个参数必须是数组Read More

应该像

<a href="{{ action('[email protected]', ['id' => 1]) }}">Product View</a> 
+1

从这个API这里https://github.com/laravel/framework/blob/5.4/src/Illuminate/Contracts/Routing/UrlGenerator.php#L62第二个参数不需要是一个数组,因为该方法将包装它在一个数组中,如果它不是一个数组。 –