mardi 1 décembre 2015

eloquent using scopeSomeName() vs someName()

whats the difference between using in eloquent

class SomeModel extends Model{
    public function active(){
        return $this->where('active','=',1);
    }
}

vs:

class SomeModel extends Model{
    public function scopeActive($query){
        return $query->where('active','=',1);
    }
}

I can use them both the same way and I am getting the same results...

$SomeModel->active()->get();

is there any advantage to the "scope prepend" way?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire