Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to know whether the current method was used in a chained call?

Tags:

laravel

php-7

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?

like image 786
Umair Ahmed Avatar asked Nov 09 '17 10:11

Umair Ahmed


People also ask

Is it possible to invoke chained methods in Java if so how will you invoke?

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.

Which of the following is also known as chaining method?

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.

Can you chain methods in Java?

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.

What are chain calls?

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.


1 Answers

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

like image 151
A. Dabak Avatar answered Oct 25 '22 11:10

A. Dabak