简体   繁体   English

Laravel路由组显示404页

[英]Laravel route group displays 404 page

I have route group and able to display the index page but when I tried to access the other route it returns 404 page not found. 我有路由组并且能够显示索引页面,但是当我尝试访问其他路由时,它返回404页面未找到。 What am I missing here? 我在这里想念什么?

Route: 路线:

Route::group(array('domain' => env('CLUBSITE1')), function () {
    Route::get('/', '\App\Http\Controllers\Club1\IndexController@index');
    Route::get('/news', '\App\Http\Controllers\Club1\IndexController@news');
});

Controller 调节器

namespace App\Http\Controllers\Club1;

use App\Http\Controllers\Controller;
class IndexController extends Controller {

    public $data;

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

    public function news() {
        return view('clubs.news');
    }
}

If you want to separate directories between controllers, you can do it like this: 如果要在控制器之间分隔目录,可以这样做:

Route::group(['domain' => env('CLUBSITE1'), 'namespace' => 'Club1'], function () {
    Route::get('/', 'IndexController@index');
    Route::get('/news', 'IndexController@news');
});

There is a debug method to determine what causes the problem: 有一种调试方法可以确定导致问题的原因:

Route::group(['domain' => env('CLUBSITE1'), 'namespace' => 'Club1'], function () {
    Route::get('/', 'IndexController@index');
    Route::get('/news', function() { return 'hello, world'; });
});

Then send a request to /news , if you see hello, world indicates your project configuration cause the problem, if not indicates your code causes the problem. 然后将请求发送到/news ,如果您hello, world表示您的项目配置导致了问题,如果不是,则表明您的代码导致了问题。

Have you tried to access via "index.php/news"? 您是否尝试通过“ index.php / news”访问?

If it works, then it's .htaccess problem. 如果有效,则为.htaccess问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM