mardi 25 juin 2019

Using collection with filter return model objects

In my laravel 5.7 I use collection with filter, but I would liek to return not integer value I set to this filter, but model objects on filtered values, like :

$selectedSubscriptions = collect($tempSelectedSubscriptions)->filter(function ($item) {
    $nextTempSelectedSubscription = SiteSubscription::find($item);
    if ($nextTempSelectedSubscription !== null) {
        return (object)['id' => $nextTempSelectedSubscription->id, 'name' => $nextTempSelectedSubscription->name];
    }
});

How can I do this ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire