简体   繁体   English

Laravel 5.4路由不起作用

[英]Laravel 5.4 Route is not working

I am new in Laravel. 我是Laravel新手。 I use Laravel 5.4. 我使用Laravel 5.4。

My Route file is : 我的路线文件是:

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();
Route::group(['middleware' => 'auth'], function () {
    Route::group(['prefix' => 'admin'], function () {
        Route::get('/', 'HomeController@index')->name('dashboard');
        Route::get('home', 'HomeController@index')->name('home');
        Route::get('/users', 'UserController@index')->name('users');
    });
});

When I use url in browser admin/home its working , but When I just use admin/ it redirecting me to Welcome page. 当我在浏览器admin/home使用url时,其工作正常,但是当我仅使用admin/它将重定向到“欢迎”页面。

simply it's not working when I use url http://appurl/admin/ but it is working when I use http://appurl/admin/home When I am wrong ? 只是当我使用网址http:// appurl / admin /时它不起作用,但是当我使用http:// appurl / admin / home它却起作用当我输入错了吗?

MY Home Controller :: 我的家庭控制器::

<?php

namespace App\Http\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('admin/dashboard');
    }
}

I noticed when I remove this: 我注意到,当我删除此:

Route::get('/', function () {
    return view('welcome');
});

I will work for http://appurl/admin/ 我将为http://appurl/admin/

you are missing / before home. 你失踪了/回家之前。

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();
Route::group(['middleware' => 'auth'], function () {
    Route::group(['prefix' => 'admin'], function () {
        Route::get('/', 'HomeController@index')->name('dashboard');
        Route::get('/home', 'HomeController@index')->name('home');
        Route::get('/users', 'UserController@index')->name('users');
    });
});

But I am little bit confused. 但是我有点困惑。 Why you are calling same function HomeController@index twice. 为什么要两次调用同一函数HomeController@index

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

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