I want to perform additional operations when a set of function are called in a chain.
I have seen this happening in Laravel query builder but I wasn't able to find the incumbent logic behind it. It defines where clauses in a set, if they are chained and separate otherwise (In the whereNested function callback).
$q->whereNested(function (Builder $q) {
// Generates "Where (first = 1 and second = 2) or third = 3"
$q->where('first', 1)->where('second', 2);
$q->orWhere('third', 3);
});
Is there a way to know this while executing the function? If not, can someone point me to the logic used by Laravel?
Method chaining in Java is a common syntax to invoke multiple methods calls in OOPs. Each method in chaining returns an object. It violates the need for intermediate variables.
Method chaining, also known as named parameter idiom, is a common syntax for invoking multiple method calls in object-oriented programming languages. Each method returns an object, allowing the calls to be chained together in a single statement without requiring variables to store the intermediate results.
In Java, method chaining is the chain of methods being called one after another. It is the same as constructor chaining but the only difference is of method and constructor.
It's a recorded message, which means you don't have to call hundreds of people directly, the recipients don't have to call anyone, and you can be sure everyone got the same message. Automation helps people use telephone chains to get the same message, so no one in your organization is left hanging.
you can use the php function debug_backtrace
to get a list of all the called functions, as for the logic used you can find it in
where
orWhere
whereNested
all three methods are in the query builder class Illuminate/Database/Query/Builder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With