Eloquent: How to Order Results by Mutator Attribute?
Recently I've encountered a situation and want to share a quick solution with you guys. Laravel has quite an awesome feature of Mutators - you can define extra fields in your Eloquent models that are dynamically calculated. But orderBy doesn't work with them, so what can we do?
First, I will remind you how it works. Imagine, you have Client.php model and fields first_name and last_name. You can define full_name attribute like this: