Комментарии:
thank you a lot!
ОтветитьJust few days ago I used raw ordering, I needed a way to pin 📌 the currently selected item to the top of a returned collection so it shows in a grid always on top in the edit blade view .
ОтветитьThat’s not a mutator it’s an accessor.
Accessor: getFullNameAttribute
Mutator: setFullNameAttribute
How should we do data sorting for encrypted data in db table, say for example firstname and lastname of users table ?
Ответитьmutator must not be used for query condition.
ОтветитьIn almost every situation is better to do that kind of actions on db level.
ОтветитьWhat is Accessor, then?..
ОтветитьThank you, what is theme you use in phpstorm ?
ОтветитьMutators can also get pretty ugly. I've seen some that depend on loaded relationships. Trying to sort by them will absolutely kill performance.
For this particular query, the best improvement I can think about is to take advantage of lazy collections at the end. ( cursor() instead of get() ). Who knows? It might even make the performance drop from the full_name mutator be negligible.
Thank you! Can I use sortby on encrypted field?
ОтветитьGreat example, explanation and analyse!
ОтветитьI did
->orderBy('first_name')
->orderBy('last_name')
->get()
Even better would be just to create a permanent column for full_name in the database table with before insert trigger where i would concatenate first and last name into this new value. Depending on the size of the dataset concatenation could be very expensive to do on millions of rows in table on the fly for the purpose of ordering.
ОтветитьTo keep that code clean and bug free probably there should be a way to describe a way to use mutators in orderBy, where and may be some other functions. Like we have get and set for an attribute. After some time and migrating fully to new attribute syntax it would be a good thing to implement by someone who actually needs this in their projects.
So you can keep your code related to the mutator in the single place.
Amazing things thank you povilas
ОтветитьWhy not use Virtual Column on database level?
ОтветитьThanks :)
ОтветитьHi sir ..... As as junior dev . i am not having exposure to Android development but in my company there area lots of project comes on mobile development is Flutter is good to go & does it helps to build my career or else moving to Native android development is good . give a suggestion sir thanks in advance sir
ОтветитьCan we also combine 'where' with 'CONCAT' in DB level? where full_name like something for searching purposes.
Ответитьloved it...
Ответитьwhy not just use the last name if you're gonna sort out the records by Lastname + Firstname ?
in that way, you'd avoid concatenating the strings in the query
So, in the spirit of debate, I ran both concat and 2 order by method on sorting 2 columns together.
With concat: 0.00047 sec (0.47 ms) on average,
with 2 order by clauses: 0.111 sec (111 ms) on average.
I ran it against ~30,000 records (a bit lower than that).
Therefore it's significantly quicker to just concat the columns on MySQL side.
sir you are great
ОтветитьCould use 2 order by instead of the concat. I don't think it helps unless you want to use that concat in the view directly, but in our case we have the accesor. I would use 2 order by calls , one on last name and second on first name and then use the accesor for the full name on the models. :) wonder if that would be faster as it would not concat 10k rows :)
ОтветитьThanks, Not needed to conctat the 2 fields for ordering in my opinion, 2 orderby after eachoter
Ответить