Hi,
I'm using an anonymous function to resolve a field called 'trashed'. This works directly with Laravel's soft deletes.
'trashed' => [
'type' => Type::boolean(),
'description' => 'Whether the item has been trashed',
'selectable' => false,
'resolve' => function (\App\Models\AssetType $type) {
return $type->trashed();
}
]
The problem is, within my query I actually use $fields->getSelect(). I don't want trashed to be selectable but I do want $type->trashed() to be able to retrieve the deleted_at field from the database.
Is there any way I can make it so that when requesting the trashed field, deleted_at is added to the getSelect() array and retrieved as such?
I guess the only other way I can do it is simply resolve deleted_at as my field and return it as a string which will either be null or the deleted timestamp - I'd just rather have a boolean that does this
Thanks..
Try adding 'always' => ['deleted_at'] to trashed array
@rebing - now that could be very helpful! Thanks very much.
@chrispage1 Did it work?
@rebing - it certainly did thank you. I've just applied it. Selectable flag still has to be set as false and the resolve method defined. Here's an example of how I've just used it for anyone searching -
'created' => [
'type' => Type::string(),
'always' => ['created_at'],
'selectable' => false,
'resolve' => function (Booking $booking) {
return $booking->created_at->format('c');
}
]
So with the above code, created_at is included as one of the select fields when using $fields->getSelect() in the query resolver.
Most helpful comment
@rebing - it certainly did thank you. I've just applied it. Selectable flag still has to be set as false and the resolve method defined. Here's an example of how I've just used it for anyone searching -
So with the above code,
created_atis included as one of the select fields when using$fields->getSelect()in the query resolver.