【问题标题】:Laravel Admin route not working but others areLaravel Admin 路由不起作用,但其他路由不起作用
【发布时间】:2019-11-03 18:16:21
【问题描述】:

我的 Laravel 项目有问题。我创建了一个管理路由组 (domain.co/admin/)。根/admin/ 在某一时刻工作,然后我添加了一些页面,从那时起更新了作曲家、安装了学说/dbal 并安装了 chart.js。现在由于某种原因,/admin/ 路由不再起作用,但所有其他路由都正常工作。

我的 web.php 路由如下所示:

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

Auth::routes(); // tried commenting this out

Route::middleware(['web','auth','rolecheck:Super'])->prefix('admin')- 
    >group(function(){
        Route::get('/', 'AdminController@index');
        Route::get('/test', 'AdminController@index');
        Route::get('/test2', 'AdminController@test');
    ....
});

...

还有更多的路线组也可以使用

/admin/ 给了我一个权限错误。 /admin/test/ /admin/test2/ 工作正常

这里是控制器

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AdminController extends Controller
{
    public function index(){
        echo '2';
        //return view('admin.dashboard');
    }

    public function test(){
        echo '1';
    }

}

.htaccess 没有显示任何奇怪的东西(默认来自 laravel)。我也试过清除缓存。

我在 /etc/httpd conf 文件中没有发现任何内容。

我已经厌倦了查看“管理员”这个词的所有代码,但找不到任何指向为什么它说权限被拒绝的任何东西。

如果我将前缀更改为“admins”,它会起作用,所以我猜测 laravel 的某些部分正在阻止 admin/ 路由。我还能在哪里查看它被阻止的位置。

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    如果您有“admin”文件夹,请检查您的公用文件夹,然后重命名它。就我而言,这是造成这种行为的原因。folders structure

    【讨论】:

      【解决方案2】:

      检查你的 laravel 目录中的 config/auth 文件并检查其中的守卫和提供者数组,默认如下所示。

      'providers' => [
              'users' => [
                  'driver' => 'eloquent',
                  'model' => App\User::class,
              ],
              'admins' => [
                  'driver' => 'eloquent',
                  'model' => App\Admin::class,
              ],
      

      【讨论】:

      • 我的看起来像这样 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', 'hash' => false, ], ], 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\User::class, ], // 'users' => [ // 'driver' => 'database', // 'table' => 'users', // ], ],没有什么说管理员
      【解决方案3】:

      将这些文件(.htaccess、index.php、favicon.ico、robots.txt)从/public 文件夹复制/粘贴到/public/admin 文件夹。

      编辑 /public/admin/index.php 文件并将“/..”添加到所有 3 个必需的 php 文件中:

      来自

      require __DIR__.'/../vendor/autoload.php';
      

      require __DIR__.'/../../vendor/autoload.php'; 
      

      【讨论】:

        猜你喜欢
        • 2017-10-31
        • 2016-11-05
        • 2015-01-26
        • 2015-03-13
        • 2018-08-01
        • 2019-12-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多