Php 如何使用laravel在一个post请求中从多个表单获取值?
阿贾克斯: 例如,对于功能:Php 如何使用laravel在一个post请求中从多个表单获取值?,php,jquery,ajax,laravel-5.4,Php,Jquery,Ajax,Laravel 5.4,阿贾克斯: 例如,对于功能: public function finalSubmit(Request $request) { var_dump($_POST); $var1 = $this->addPriceDetails1($request->form1); $var2 = $this->addProductDetails1($request->form2); $var3 = $this->addAdditional
public function finalSubmit(Request $request)
{
var_dump($_POST);
$var1 = $this->addPriceDetails1($request->form1);
$var2 = $this->addProductDetails1($request->form2);
$var3 = $this->addAdditionalInformation1($request->form3);
//$var4 = $this->addImages($imagesform);//you dont't have
$imagesform
return response()->json(["response"=>"success"]);
}
在这里,当我尝试回显$priceInfo->Id
的值时,它回显“0”。我不知道为什么
有了这个,我得到了FatalErrorException..对字符串上的成员函数input()的调用
var\u dump($\u POST)
为我提供了一个表单值数组
更新:
public function addPriceDetails1($request)
{
$priceInfo = new priceInfo ;
$priceInfo->id=$this->getpriceDetailsId();
$priceInfo->SKUID=$request->input('skuid');
echo($priceInfo->id);
//return $request->all();
}
这是我的getpriceDetailsId()函数。如果您以对象
的形式访问输入查询,当它是字符串
时,您可以将查询字符串转换为数组以进行类似的访问,则会出现此错误
public function getpriceDetailsId()
{
$id = mt_rand(1000000, 9999999);
$id="PD".$id;
$count=priceInfo::select('id')->where('id',$id)->count();
if($count==0)
{
return $id;
}
else
{
$this->getpriceDetailsId();
}
}
希望这个帮助能起作用。但是我没有得到$priceInfo->id的值。好吧,为此你需要告诉我getpriceDetailsId()
在哪里?是在同一个控制器上还是在其他控制器上?为什么要标记ID?您的ID不是int
,因为我看到您在其中添加了字符串$ID=“PD”。$ID代码>?,如果($count==0)为0,为什么只返回$id
?我不知道你为什么要写这个函数及其用途^^^是的..我的ID是字符串..我在$count==0 bcz时返回它,该ID不应重复。我不知道你的系统,所以我无法帮助你使用函数,因为我不知道它的用途。
public function getpriceDetailsId()
{
$id = mt_rand(1000000, 9999999);
$id="PD".$id;
$count=priceInfo::select('id')->where('id',$id)->count();
if($count==0)
{
return $id;
}
else
{
$this->getpriceDetailsId();
}
}
public function addPriceDetails1($request)
{
parse_str($request, $input);
$priceInfo = new priceInfo ;
$priceInfo->id = $this->getpriceDetailsId();
$priceInfo->SKUID = $input['skuid'];
echo($priceInfo->id);
}