从url获取要插入到其中的ID(Laravel)
我像这样插入url:“export/1-2-18”。1、2、18是表的ID。 该ID由复选框选中,因此它可以是表中的任何数字 天气是这样的从url获取要插入到其中的ID(Laravel),laravel,where-in,Laravel,Where In,我像这样插入url:“export/1-2-18”。1、2、18是表的ID。 该ID由复选框选中,因此它可以是表中的任何数字 天气是这样的 <a href ="{{ url('export',['id'=> $a ]) }}" class="btn btn-info export" id="export-button"> Export file </a> 我已将url从“1-2-18”替换为“1,2,18”,并插入到,其中,但我刚刚收到一个结果 如何获得所有结
<a href ="{{ url('export',['id'=> $a ]) }}" class="btn btn-info export" id="export-button"> Export file </a>
我已将url从“1-2-18”替换为“1,2,18”,并插入到,其中,但我刚刚收到一个结果
如何获得所有结果?提前感谢。where的第二个参数错误。您必须输入值数组,而不是字符串数组(['1,2,18']应该是[1,2,18])
可以使用explode()方法
public function exportFile($id){
$rp = str_replace('-',',',$id);
echo ($rp);
$products = DB::table('duan')
->whereIn('MaDA', [$rp])
->get();
dd($products);
$products= json_decode( json_encode($products), true);
return Excel::create('ThongTinDuAn', function($excel) use ($products) {
$excel->sheet('sheet name', function($sheet) use ($products)
{
$sheet->fromArray($products);
$sheet->getStyle('A2:E2')->getAlignment()->setWrapText(true);
});
})->export('xlsx');
}
$rp = explode('-',$id);
$products = DB::table('duan')
->whereIn('MaDA', $rp)
->get();