php – 在子文件夹中定义Laravel 5路由并通过控制器显示它

我有Laravel 5.2.45应用程序.

我有这样的控制器结构:

App
    Http
        Controllers
            Admin
                AdminController.php

我在AdminController.php里面

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;

class AdminController extends Controller 
{

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

public function index()
{
    return view('admin.home');
}

}

我有这样的视图文件夹结构:

views
    admin
        home.blade.php

在我的routes.php里面我有

Route::get('/admin/home', 'Admin\AdminController@index');

所以当我输入时,我正试图得到它… / admin / home browser在admin文件夹中显示home.blade.php.

我的routes.php:

Route::auth();

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

Route::get('/home', 'FrontController@index');

Route::get('/add_user', 'FrontController@user');

Route::group(['prefix', 'admin', 'namespace' => 'Admin'], function() {
    Route::get('home', 'AdminController@index');
});

最佳答案 路由定义中缺少前缀.纠正它看起来像这样:

<?php
   Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
       Route::get('/home', 'AdminController@index');
   });

Now, try base_url/admin/home in your browser and it should work.

点赞