【问题标题】:Laravel: Routing all the routes fileLaravel:路由所有路由文件
【发布时间】: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文件,我试了一下。请检查

标签: laravel routing


【解决方案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 中不存在的视图。

【讨论】:

  • 谢谢我检查了它:它显示 C:\xampp\htdocs\larve>php artisan route:list [ReflectionException] Class Modules\Course_Entry\Controllers\CourseController 不存在
  • 我添加了图像,请它,它说的所有文件都丢失了。我第一次在 laravel 中使用模块,从过去 4 天开始,我试图找出问题所在。但我找不到它。
  • @Learning_to_solve_problems 您能否提供您使用什么来处理模块?为此,我向您推荐caffeinated/modules package。它有据可查,可以避免您头疼。无论如何,现在你的问题是 Laravel 没有检测到你的 CourseController 类。也许你的命名空间或类名中有错字,如果已经正确,请尝试运行composer dumpautoload,这将在你的composer.json 文件中注册添加到 psr-4 的类。
  • 谢谢我检查了,没有错字,我认为我的基本控制器或路由有问题。我已经添加了,请查收。
  • 而且我没有使用任何东西来处理模块。我尝试手动添加它们:kamranahmed.info/blog/2015/12/03/… 使用此方法
猜你喜欢
  • 1970-01-01
  • 2019-10-05
  • 2019-09-03
  • 2014-10-09
  • 2013-08-07
  • 2020-08-26
  • 2013-09-05
  • 2020-10-17
  • 1970-01-01
相关资源
最近更新 更多