大家好,我正在尝试检索我的列,该列有一个带有 json 响应的 zerofill 规范,但似乎 php 忽略了那里的零,所以我尝试使用str_pad
与 zerofill 做相同的工作,但它也忽略了它! !那么我该如何解决这个问题呢?这是我的代码
public function getGeneralPost(){
$post =Post::inRandomOrder()->orderBy('created_at', 'DESC')->get();
foreach ($post as $item){
$categories = Category::where('id' , $item->post_subtype)->select('category_title')->first();
$categories_type = Category::where('id' , $item->post_type)->select('category_title')->first();
$item->post_subtype = $categories->category_title;
$item->post_type = $categories_type->category_title;
$item->id = str_pad($item->id ,10,'0',STR_PAD_LEFT);// here I am usting str_pad
}
$success['posts'] =$post;
return response()->json(['code'=>'success','success' => $success], $this->successStatus);
}