Комментарии:
In the next video, we will be looking at why is this happening by looking into how the when works under the hood.
ОтветитьThanks sir
ОтветитьI'm sorry, the title might not be correct, because what you show to developers (juniors) will lead them to may not use "when" ever.. "when" should be used mainly to build queries. What you did in every way is not recommended to loop over 100k with if or when both of them are useless;
Anyway Thank you for all your vids !
I'm looking for solution.. how can we search database on the basis of relationship.. like i have a situation.. a field technology and other is version.. both has different tables and the pivot.. i want to search a technology with specific version if exists in relation
ОтветитьThe message that you output is shorter so it takes less time….
ОтветитьOne thing to always keep in mind is, if a method passes a closure (an inner function) it would take longer time to execute.
Example of closure is the one you just tested:
$user->when(<argument>, function() { <callback> });
Of course there are cases where you need to use a closure, like when doing complicated queries. And remember you always have an option to cache the query.
What is your VSCode setup? (extensions, etc...)
ОтветитьThanks to you great content , i wonder if you can check the performance difference between whereHas and joins and wherein in retrieving Relationships data
Ответить`->when` creates an eloquent builder instance and therefore is much slower, compared to the plain if.
@OP Please check the documentation before comparing pears and apples.
A relevant use case can be an already instantiated query builder and adding builder conditions depending on the current system state. when will be more readable.
I understand completely the ide of executing the code 100, 000 times but I am pretty sure that executing a single time both would not have a great difference, of course, there are great use cases for when() and others for if() but generally it would not have that amount of impact in terms of number of executions.
Ответить