Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Routes 在Laravel 8中未找到404_Routes_Optional Parameters_Laravel 8 - Fatal编程技术网

Routes 在Laravel 8中未找到404

Routes 在Laravel 8中未找到404,routes,optional-parameters,laravel-8,Routes,Optional Parameters,Laravel 8,路由中的可选参数有问题。当我前往时,以下路线起作用: http://localhost/orders/create/1但它不适用于http://localhost/orders/create并返回一个404错误(未找到) Route::name( 'orders.' )->prefix( 'orders' )->group( function(){ Route::get( '/create/{client?}', [ \App\Http\Controller

路由中的可选参数有问题。当我前往时,以下路线起作用:
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的客户端存在。有什么想法吗?

这是因为您正在定义路由/create/{client?},但是没有定义/create,您的脚本可能与/create/一起工作,因为客户端参数是可选的

后面的斜杠就是问题所在