移动路径文件夹后未定义路径[登录]

时间:2017-10-29 09:44:50

标签: laravel routes

我正在使用Laravel构建管理站点,并且需要让所有控制器在一个文件夹中路由模型,因此我将路由和控制器移动到此文件夹并将RouteServiceProvider.php更改为:

  <?php

  namespace App\Providers;

  use Illuminate\Support\Facades\Route;
  use Illuminate\Foundation\Support\Providers\RouteServiceProvider as 
  ServiceProvider;
 class RouteServiceProvider extends ServiceProvider
 {
 /**
 * This namespace is applied to your controller routes.
 *
 * In addition, it is set as the URL generator's root namespace.
 *
 * @var string
 */
 protected $namespace = 'App\Application\Controllers';

/**
 * Define your route model bindings, pattern filters, etc.
 *
 * @return void
 */
 public function boot()
 {
    //

    parent::boot();
 }

/**
 * Define the routes for the application.
 *
 * @return void
 */
public function map()
{
    $this->mapApiRoutes();

    $this->mapWebRoutes();

    //
}

/**
 * Define the "web" routes for the application.
 *
 * These routes all receive session state, CSRF protection, etc.
 *
 * @return void
 */
protected function mapWebRoutes()
{
    Route::middleware('web')
         ->namespace($this->namespace)
         ->group(base_path('app/Application/routes/web.php'));
}

/**
 * Define the "api" routes for the application.
 *
 * These routes are typically stateless.
 *
 * @return void
 */
protected function mapApiRoutes()
{
    Route::prefix('api')
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('app/Application/routes/api.php'));
}

}

它工作正常但却给我以下错误:

路线[登录]未定义。

这是我的路线档案:

 <?php

 Route::get('/' , 'HomeController@index');

和我的家庭控制器

<?php

namespace App\Application\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('auth');
}

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
   return view('home');
}
}

1 个答案:

答案 0 :(得分:0)

在您的路线文件中,您只需:

 <?php
 Route::get('/' , 'HomeController@index');

正如您所看到的那样,只有一个路由并且仅适用于一个页面,实际上如果您想使用$ this-&gt;中间件('auth');你应该定义它的路由。

类似的东西:

 Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');

您拒绝了$ this-&gt;中间件('auth');对于Home的控制器而言,它是强制查找重定向的登录路径。所以将构造函数更改为以下代码:

public function __construct()
{

}