Php 如何传递多个参数(请求另一个参数)

Php 如何传递多个参数(请求另一个参数),php,laravel,Php,Laravel,我正在开发一个向客户发送短信的项目 我试图在数据库中创建一个新的行,我在函数中传递了3个参数 TraitementController.php public function send_sms_reply(Request $request, Client $client, $id) { $validatedData = $request->validate ([ 'expediteur' => 'Reponse',

我正在开发一个向客户发送短信的项目

我试图在数据库中创建一个新的行,我在函数中传递了3个参数

TraitementController.php

public function send_sms_reply(Request $request, Client $client, $id)
    {

        $validatedData = $request->validate ([
            'expediteur' => 'Reponse',
            'texte' => 'required|string',
            'type' => 2,
            'conversation_id' => 'required|numeric',
            'client_id' => $client->id,
            'user_id' => 'required|numeric',
            'statut' => 0,
        ]);

        $sms_cree = Sms::create($validatedData);

[...]

}
web.php

Route::post('envoyer/sms', 'TraitementController@send_sms_reply')->name('traitements.send_sms_reply');

你知道我为什么会出现这个错误吗?

像下面这样更改你的路由,这样它就可以接受
发送短信回复功能所需的参数

Route::post('envoyer/sms/{client}/{id}', 'TraitementController@send_sms_reply')->name('traitements.send_sms_reply');
要将多个参数传递给route,可以在表单中执行类似的操作

<form method="post" action="{{ route('traitements.send_sms_reply', ['client' => $conversation->client, 'id' => Auth::user()->id)] }}">
@csrf
/* Your code */
</form>

@csrf
/*你的代码*/

谢谢

如下图所示更改您的路由,这样它就可以接受
发送\u sms\u回复功能所需的参数

Route::post('envoyer/sms/{client}/{id}', 'TraitementController@send_sms_reply')->name('traitements.send_sms_reply');
要将多个参数传递给route,可以在表单中执行类似的操作

<form method="post" action="{{ route('traitements.send_sms_reply', ['client' => $conversation->client, 'id' => Auth::user()->id)] }}">
@csrf
/* Your code */
</form>

@csrf
/*你的代码*/

谢谢

“您知道我为什么会出现此错误吗?”是的,因为您只向函数传递了2个参数,而它需要3个。我不明白您为什么要在表单参数中传递
Auth::user()->id
?虽然你可以直接在控制器中得到它。在控制器中,您可以直接访问Auth::id()@我知道GrumpyCrouton,但通常当我使用请求参数时,我不需要通过any@DilipHirapara谢谢你,我不知道“你知道我为什么会出现这个错误吗?”是的,因为你只向函数传递了2个参数,它需要3个。我不明白你为什么在表单参数中传递
Auth::user()->id
?虽然你可以直接在控制器中得到它。在控制器中,您可以直接访问Auth::id()@我知道GrumpyCrouton,但通常当我使用请求参数时,我不需要通过any@DilipHirapara谢谢,我不知道嘿,我已经试过了,我得到了
array\u map():参数2应该是数组,int给定
$conversation->client
应该是对象确保它是对象try
dd($client)
是的,我尝试了这个,dd($client->id)并且它返回了客户端的id,
$conversation->client
路由模型绑定的输出可能是您想要对客户端参数执行的操作。嘿,我已经试过了,我得到了
array\u map():参数2应该是数组,给定int
$conversation->client
应该是对象确保它是对象try
dd($client)
是的,我试过这个和dd($client->id)ad它返回的是客户端的id,
$conversation->client
路由模型绑定的输出可能是您希望对客户端参数执行的操作。