【问题标题】:Not found 404 in Laravel 8在 Laravel 8 中找不到 404
【发布时间】:2020-10-12 18:11:22
【问题描述】:

我在路由中的可选参数有问题。当我去时,以下路线有效: http://localhost/orders/create/1 但它不适用于 http://localhost/orders/create 并返回 404 错误(未找到)

    Route::name( 'orders.' )->prefix( 'orders' )->group( function(){

        Route::get( '/create/{client?}', [ \App\Http\Controllers\OrderController::class, 'create' ] )->name( 'create' );

    } );

    public function create( Client $client = null ){

        return [ $client ];

    }

我已经检查过了,ID=1 的客户端存在。有什么想法吗?

【问题讨论】:

    标签: routes optional-parameters laravel-8


    【解决方案1】:

    那是因为您正在定义路由 /create/{client?} 但 /create 未定义,可能您的脚本与 /create/ 一起使用,因为客户端参数是可选的。

    斜杠是问题所在。

    【讨论】:

      猜你喜欢
      • 2021-01-27
      • 2021-07-29
      • 2021-08-06
      • 2021-09-06
      • 2019-12-02
      • 2021-09-28
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多