我正在使用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)
ProjectController:
<?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');
}
}
答案 0 :(得分:1)
运行php artisan route:list
。如果缺少路由,请确保它们应该位于哪个路由文件中。然后问题是Laravel没有注册这个文件。
创建或使用现有的RouteServiceProvider
来映射您丢失的文件。
更新:
但它显示错误:未找到视图[includes.message-block]。 (查看:C:\ xampp \ htdocs \ larve \ app \ Modules \ Log_in_blog_post \ views \ welcome.blade.php)
此错误与第一个错误无关,您可能正试图@include
welcome.blade.php
中不存在的视图。