为什么不forget()
从集合中删除created_at
。尝试过except()
也不起作用
$descRequest = request()->descTable;
$wherePage = request()->onPage ?? 1;
$rowsPerPageRequest = request()->rowPerPage ?? 2;
$sortedByRequest = request()->sortBy ?? 'generatednumber_id';
$makeData = Generatenumberid::withCount([
'generateNumberIdGeneratedNumber as total_generated_number'
])
->orderBy($sortedByRequest, $descRequest)
->paginate($rowsPerPageRequest, ['*'], 'page', $wherePage);
$mapMakeData = $makeData->map(function ($item, $key) {
$carbonDateString = $item->created_at->format('d F Y');
$carbonForHuman = $item->created_at->diffForHumans();
$item->id = $item->id;
$item->generatednumber_id = $item->generatednumber_id;
$item->total_generated_number = $item->total_generated_number;
$item->time_generated = "{$carbonDateString} - {$carbonForHuman}";
return $item;
});
$collectMap = collect($mapMakeData->all());
$collectMap->forget('created_at');
dd($collectMap->all());
预期结果
给定的列已从集合中删除
"id" => 39
"generatednumber_id" => "CELLNUMBS-|2019-02-03|-0023"
"updated_at" => "2019-02-03 13:25:01"
"total_generated_number" => 0
"time_generated" => "03 February 2019 - 1 day ago"
答案 0 :(得分:0)
我认为这是因为您正在处理数组的集合。 forget()
或except()
仅适用于集合。
因此,这应该可行。
//
//
//
$collectMap = collect($mapMakeData->all());
$collectMap->map(function($item) {
return array_except($item, 'created_at');
});
dd($collectMap->all());