xxxxxxxxxx
// dont copy this
$all_items = $this->excel->oldest('excel_data.id')->get();
$resource = collect()->range(0, 178)->map(function ($value) use ($all_items) {
$instance = $all_items[$value] ?? null;
return [
'main_rows' => $instance?->main_rows ?? null,
];
});
xxxxxxxxxx
collect($deliver_addresses)->map(function ($address) use ($input) {
$address['id'] = $input['id'];
$address['a_new_attribute'] = $input['a_new_attribute'];
return $address;
});
xxxxxxxxxx
//After Eloquent query you can modify rows by using •map()• function in Collections.
$users = User::where('role_id', 1)->get()->map(function (User $user) {
$user->some_column = some_function($user);
return $user;
});