ReflectionException类App \ Http \ Controllers \ StaticPagesController @ faq不存在Laravel-5
I cloned this todstoychev/Laravel5Starter from Github and installed it.
After creating this StaticPagesController
controller and updating my routes.php file. The controller does not seem to work. For some reason i keep getting the following error.
ReflectionException in ControllerInspector.php line 32:
Class App\Http\Controllers\StaticPagesController@faq does not exist
My routes.php file
<?php
// Admin routes
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () {
Route::controller('permissions', 'AdminPermissionsController');
Route::controller('settings', 'AdminSettingsController');
Route::controller('roles', 'AdminRolesController');
Route::controller('users', 'AdminUsersController');
Route::controller('/', 'AdminController');
});
// Public and user routes
Route::controller('contacts', 'ContactsController');
Route::controller('users', 'UsersController');
Route::controller('/', 'IndexController');
Route::controller('faq', 'StaticPagesController@faq');
My StaticPagesController.php file
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class StaticPagesController extends Controller
{
public function faq(){
return 'this is faq page';
}
}
I have tried composer update
, php artisan acl:update
, composer dumpautoload
to no avail.
Please help me. Thanks
我克隆了这个 todstoychev / Laravel5Starter 并安装它。 p>
创建此 我的routes.php文件 strong> p>
我的StaticPagesController.php文件 strong> p>
我已经尝试 请帮帮我。 谢谢 p>
div> StaticPagesController code>控制器并更新我的routes.php文件后。 控制器似乎不起作用。 由于某种原因,我不断收到以下错误。 p>
ControllerInspector.php第32行中的ReflectionException:
Class App \ Http \ Controllers \ StaticPagesController @ faq不存在
code> pre>
&lt;?php
//管理员 routes
Route :: group(['prefix'=&gt;'admin','namespace'=&gt;'Admin'],function(){
Route :: controller('permissions','AdminPermissionsController'); \ n
Route :: controller('settings','AdminSettingsController');
Route :: controller('roles','AdminRolesController');
Route :: controller('users','AdminUsersController ');
Route :: controller('/','AdminController');
});
//公共和用户路由
Route :: controller('contacts','ContactsController') ;
Route :: controller('users','UsersController');
Route :: controller('/','IndexController');
Route :: controller('faq','StaticPagesController @ faq');
code> pre>
&lt;?php
namespace App \ Http \ Controllers;
use Illuminate \ Http \ Request;
use App \ Http \ Requests;
use App \ Http \ Controllers \ Controller;
class StaticPagesController扩展Controller
{
公共函数faq(){
return'这是常见问题页';
}
}
code> pre>
composer update code>,
php artisan acl:update code>,
composer dumpautoload code>无济于事。 p>
With this line:
Route::controller('faq', 'StaticPagesController@faq');
You are telling Laravel that the controller for faq
shoule be StaticPagesController@faq
. The Route::controller
method sets an entire controller for a route, it does not specify a method to be used on that route, Laravel handles this internally. Take a look at your error to prove my point:
Class App\Http\Controllers\StaticPagesController@faq does not exist
It is looking for class StaticPagesController@faq
not StaticPagesController
as you are intending.
Unless you are building an API using REST, you should not use the controller
method and instead specify your routes explicitly, i.e.
Route::get('faq', 'StaticPagesController@faq');
This will use the faq
method on your controller when the user makes a GET request to the URI faq
. If you insist on using the controller
method, then remove the @faq
from the second argument and you will be good, although I'm pretty sure Laravel expects the methods index, show, create, etc to be in your controller. I suggest taking a look at the Laravel 5 Fundamentals video course to help you get a better understanding.