Laravel控制器子文件夹路由

Laravel控制器子文件夹路由

本文介绍了Laravel控制器子文件夹路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel的新手.为了使我的应用程序井井有条,我想将控制器放入控制器文件夹的子文件夹中.

I'm new to Laravel. To try and keep my app organized I would like to put my controllers into subfolders of the controller folder.

controllers\
---- folder1
---- folder2

我试图路由到控制器,但是laravel找不到.

I tried to route to a controller, but laravel doesn't find it.

Route::get('/product/dashboard', 'folder1.MakeDashboardController@showDashboard');

我做错了什么?

推荐答案

对于上述Laravel 5.3:

For Laravel 5.3 above:

php artisan make:controller test/TestController

这将创建test文件夹(如果它不存在),然后在其中创建TestController.

This will create the test folder if it does not exist, then creates TestController inside.

TestController将如下所示:

<?php
namespace App\Http\Controllers\test;

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

class TestController extends Controller
{
    public function getTest()
    {
        return "Yes";
    }
}

然后您可以通过以下方式注册路线:

You can then register your route this way:

Route::get('/test','test\TestController@getTest');

这篇关于Laravel控制器子文件夹路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:20