您需要namespace 来实现这一点。
在您的控制器文件夹中创建一个名为 merchant 的目录并将您的 ProductController.php 放在 Merchant 目录中。
然后打开您的ProductController.php 并在文件顶部使用以下命名空间。
<?php namespace Merchant;
class ProductController extends /BaseController
{
然后编辑你的路由文件:
Route::get('index', 'Merchant\ProductController@showIndex');
删除Route::group(array('prefix' => 'merchant'), function()。当您有多个路由的公共 url 时使用的前缀。
例如:
http:://laravel.com/xyz/products
http:://laravel.com/xyz/category
http:://laravel.com/xyz/posts
这里xyz 在每个网址中都很常见。所以,在这种情况下,您可以使用前缀为xyz的组路由
还有一件事,我可以看到,您使用了资源控制器。
Route::resource('index', 'ProductController@showIndex');
Route::resource('product', 'CategoryController@showIndex');
Route::resource('general', 'GeneralController@showIndex');
你知道吗,默认情况下,对于资源控制器,Laravel 会生成 7 个路由。所以,在使用资源控制器的时候不需要创建@showIndex函数。
Route::resource('index', 'ProductController');
Route::resource('product', 'CategoryController');
Route::resource('general', 'GeneralController');
更多关于资源控制器:
http://laravel.com/docs/controllers#resource-controllers