Answer the question
In order to leave comments, you need to log in
How to disable global scope for one controller?
I implemented a scope as a separate class and connected it to the boot model https://laravel.com/docs/6.x/eloquent#global-scopes
everything works fine throughout the project, now I need to disable this scope for one controller so that it is not used in :
public function update(Post $post, Request $request) {}
public function delete(Post $post) {}
/**
* @inheritDoc
*/
protected static function boot(): void
{
parent::boot();
in_array(VisibleScope::class, self::$disabledGlobalScopes) || static::addGlobalScope(new VisibleScope());
}
/**
* @var array
*/
protected static $disabledGlobalScopes = [];
/**
* @param string $scope
*/
public static function disableGlobalScope(string $scope): void
{
static::$disabledGlobalScopes[] = $scope;
}
Answer the question
In order to leave comments, you need to log in
https://laravel.com/docs/6.x/routing#route-model-b...
There are options.
public function boot()
{
parent::boot();
Route::bind('page-no-scope', function ($value) {
return App\Page::withoutGlobalScope()->firstOrFail();
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question