【发布时间】:2018-02-14 14:38:28
【问题描述】:
我正在 Laravel 中构建一个名为 Student 的模块。
我使用 Student 文件夹中的 routes.php 文件来写路由到学生模块..
当我只使用Route::get('/list', function () { return view('welcome');}); 程序时,运行良好,没有错误。
但是当我使用Route::get('/list', 'StudentController@list'); 时出现错误。
错误是,
类 App\Http\Controllers\StudentController 不存在
文件夹结构
学生监督
namespace App\Student\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class StudentController extends Controller
{
public function list(){
echo "Hello"
}
}
学生服务提供者
namespace App\Student;
use App\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class StudentServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
parent::boot();
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Define the routes for the application.
*
* @internal param Router $router
*/
public function map()
{
Route::group([
'namespace' => $this->namespace,
'prefix' => 'students',
], function ($router) {
require __DIR__ . '/routes.php';
});
}
}
【问题讨论】:
-
试试这个
Route::get('student/list', 'StudentController@list'); -
可以显示
App\Providers\RouteServiceProvider和routes.php的内容吗? -
@Kaspars 这只是students/routes.php 中的
Route::get('/list', 'StudentController@list');行。我还没有触及 RouteServiceProvider 文件。 github.com/laravel/laravel/blob/master/app/Providers/…
标签: php laravel laravel-5 laravel-routing laravel-controller