I have a collection of Items. Now, before I am sending it though my api, I want to change a value of the model (but I don't want to update my model in the database).
Now I want to loop though my collection and return it as json, but I am getting invalid Payload
.
Here is the code I perform:
$trainees = Trainee::select();
if(!$request->user()->hasPermission('read-trainees')) {
$trainees->where('status', 1)->where('visible', 1);
} else {
$trainees->with(array('user'=>function($query){
$query->select('id','firstname', 'lastname');
}));
$trainees->select('user_id');
}
$trainees->select('interested_jobs', 'graduation');
$trainees = $trainees->get();
return $trainees
->map(function ($item) {
$item->id = encrypt($item->id);
return $item;
})
->toJson();