【问题标题】:Route [test.index] not defined?路线 [test.index] 未定义?
【发布时间】:2016-08-26 05:37:25
【问题描述】:

我有 Dingo API。

这是我的 routes.php 文件:

Route::resource('test','TestController');

$api = app('api.router');
$api->version('v1',['prefix' => 'api'], function ($api) {
    $api->resource('user', 'App\Http\Controllers\API\v1\UserController');
});

在 UserController 中我只能使用 API 路由??

所以我不能做 route('test.index') 因为它给了我这个错误: 路线 [test.index] 未定义

但是 route('api.user.index') 工作正常吗?

如何使用原生 Laravel 路由,如 test.index、test.edit 等?

我看到 route() 调用 app() 函数,但我不明白它是如何工作的。这在任何地方都有记录吗?

【问题讨论】:

  • 运行这个命令php artisan route:clear然后运行php artisan route:list并在结果中寻找test.index
  • 是的,我在那里找到了 test.index。如果我运行 php artisan api:routes 我会得到一个 api 路由列表。似乎 routes() 只是调用 API 路由而不是 laravel 路由。我猜想 Dingo 以某种方式重写了 routes() 函数以仅引用 api 路由。那么我如何访问在 route:list 中找到的本地 Laravel 路由呢?

标签: php laravel laravel-5.2 laravel-routing dingo-api


【解决方案1】:

我想通了...这里讨论了这个问题: https://github.com/dingo/api/issues/918

一个拉取请求由 jenky https://github.com/dingo/api/pull/919提交

我只是运行“composer update”来获取最新的 Dingo API 开发版本,问题就解决了。

【讨论】:

    【解决方案2】:
    public function index() {
        $products = Product::latest()->paginate(5);
        return view('products.index',compact('products'))
            ->with('i', (request()->input('page', 1) - 1) * 5);
    }
    

    【讨论】:

    • 请考虑为您的答案添加一些解释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    • 2021-11-12
    • 2022-01-16
    • 2018-10-15
    • 2020-09-13
    • 2017-12-25
    • 2023-03-29
    相关资源
    最近更新 更多