Get the current model you are using Eloquent Laravel

0

I am making an implementation of a plugin, but I need to obtain the current model that laravel is using when performing some operation ... Is there a function or way to "intercept" the model that Eloquent is working on at that moment?

    
asked by Christian Irack 18.12.2017 в 23:52
source

1 answer

0

What you can do is add a function in all the models that give you the name of the model

class ModeloA extends Model
{
    public function mostrarModelo() {
       echo 'ModeloA';
    }
}
class ModeloB extends Model
{
    public function mostrarModelo() {
       echo 'ModeloB';
    }
}

and how much you have the variable

to return the model you use

$elto=ModeloA::find(1);
$modelo=$elto->mostrarModelo();
    
answered by 02.05.2018 в 17:14