Please format your code - it is very difficult to understand that word salad
Laravel sorting the alphanumeric data
Hi i am trying to sort an alphanumeric data in laravel but i have not been able to figure out how to do so
0 => "HMO Rent Guarantee Insurance - 4 Bedroom (£0 - £500pcm)"
1 => "HMO Rent Guarantee Insurance - 4 Bedroom (£501 - £3,000pcm)"
2 => "HMO Rent Guarantee Insurance - 6 Bedroom (£0 - £500pcm)"
3 => "HMO Rent Guarantee Insurance - 6 Bedroom (£501 - £3,000pcm)"
4 => "Rent Guarantee Insurance (£0 - £500pcm)"
5 => "Rent Guarantee Insurance (£3,001 - £8,000pcm)"
6 => "Rent Guarantee Insurance (£501 - £3,000pcm)"
I tried doing it this way
$data = $Product::orderByRaw("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(name, '£', -1), ' ', 1), 'pcm', 1) AS SIGNED)") ->orderBy('name') ->get()
this is the kind of data i have and i want it to show like
0 => "HMO Rent Guarantee Insurance - 4 Bedroom (£0 - £500pcm)"
1 => "HMO Rent Guarantee Insurance - 4 Bedroom (£501 - £3,000pcm)"
2 => "HMO Rent Guarantee Insurance - 6 Bedroom (£0 - £500pcm)"
3 => "HMO Rent Guarantee Insurance - 6 Bedroom (£501 - £3,000pcm)"
4 => "Rent Guarantee Insurance (£0 - £500pcm)"
5 => "Rent Guarantee Insurance (£501 - £3,000pcm)"
6 => "Rent Guarantee Insurance (£3,001 - £8,000pcm)"
i want them to be sorted in the alphabetical order as well as the numbers that are showing in the string if i try to sort it out by extracting the numbers part and with alphabetically, the alphabetic sorting comes up wrong, i am stuck here, can anyone help me figure it out thanks
Please or to participate in this conversation.