perhaps you can remove this through a controller/services/repository
where you have a function lets say
{
if ( $removeGlobalScopes) {
Product::withoutGlobalScopes()->all();
}
else
{
///
}
}
Hello my friends,
I have a problem that I want to solve but I can not figure out. First of all I would like to mention that I use Laravel 5.5 version. Here is the issue ;
<?php
class Product extends Model{
use WithPassive, WithPrivate;
public static function boot(){
parent::boot();
parent::observe( ProductObserver::class );
}
}
My model file is above. As shown in the model file, there are 2 GlobalScope traits. These are added as defaults.
SELECT * FROM `products` WHERE `products`.'is_public' = 1 AND `products`.'is_private' = 0
What I want to do is remove these global scopes according to a certain criterion.
<?php
public static function boot(){
parent::boot();
static::addGlobalScope('xxx', function(Builder $builder){
if(...){
$builder->withoutGlobalScopes([
ActiveScope::class,
PublicScope::class,
]);
}
});
parent::observe( ProductObserver::class );
}
When I dump the builder, the related global scope is deleted, though it is not actually deleted.
<?php
dump(Products::toSql());
Unfortunately, when I run the command, the global scope is still in place. I would ask your assistance in this matter.
i created a new global scope. i changed the order of adding global scope to model class. it worked like this. but it didn’t seem to me right to a solution.
Please or to participate in this conversation.