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

Viewed 112

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?

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

Related