【发布时间】:2016-10-26 18:06:02
【问题描述】:
我正在使用 Laravel 的模块化结构,我在两个模块中有一个主路由文件和 2 个路由文件。如何确保我所有的路由文件(web.php)都能完美加载?
编辑- 我尝试在 RoutesServiceProvider 文件中添加数据:
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapModuleWebRoutes1();
$this->mapModuleWebRoutes2();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/web.php');
});
}
protected function mapModuleWebRoutes1()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {-
require app_path('Modules/Course_Entry/web.php');
});
}
protected function mapModuleWebRoutes2()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require app_path('Modules/Log_in_blog_post/web.php');
});
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::group([
'middleware' => 'api',
'namespace' => $this->namespace,
'prefix' => 'api',
], function ($router) {
require base_path('routes/api.php');
});
}
}
但它显示错误:未找到查看 [includes.message-block]。 (查看:C:\xampp\htdocs\larve\app\Modules\Log_in_blog_post\views\welcome.blade.php)
项目控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class ProjectController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function nextpage1()
{
return view('Course_Entry::welcome');
}
public function nextpage2()
{
return view('Log_in_blog_post::welcome');
}
}
【问题讨论】:
-
所有路由都应该在 routes.php 文件中。
-
好的,但我正在使用具有 Routes/web.php 的 laravel 5.2,其中包含所有路由。我在这里使用模块,这些模块也有自己的路由文件。他们不工作......我该如何解决这个问题?
-
查看模块安装说明。可能,您需要将文件添加到作曲家。
-
我没有安装这些模块,我是通过这个方法制作的:kamranahmed.info/blog/2015/12/03/… 检查了它们,但它没有说要向作曲家文件添加任何内容。
-
我这里添加了RoutesServiceProvider文件,我试了一下。请检查