1

I have 2 array when one of the array is empty and sortby then it gives empty array

$first = [];
$second = ['created_at'=>2];
$third= [$first , $second];
$res = collect($third)->sortBy('created_at')->first();
dd($res);

if both array have value then it proper run. issue comes when one of array is empty. i need other array which is not empty. Thanks

2 Answers 2

1

replace :

$res = collect($third)->sortBy('created_at')->first();

by:

$res = collect($third)->sortBy('created_at')->filter(function($value) {return !empty($value);})->first();

this will remove any empty array from the result of the sort

Sign up to request clarification or add additional context in comments.

Comments

1

Try like this:

$first = collect([]);
$second = collect(['created_at'=>2]);

$third = $first->push($second)->sortBy('created_at')->first();

1 Comment

i am facing one issue in stripe on live mode.. can you tell me the solution.. actually it works fine when on test mode but on live mode when on click button 3dsecure popup open after verification it close then it not further run .. even not go in method you can find this link stackoverflow.com/questions/71322782/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.