How to Remove global scope from relation in Laravel
✔ Recommended Answer
never mind i just created a new relation
public function getDetalesWithout(){ return $this->hasMany('App\Vouchers_detale','vouchers_detale_voucher_id','id')->withTrashed()->withoutGlobalScope('App\Scopes\getVouchers');}
thanks
Source: stackoverflow.com
Answered By: Awar Pulldozer
In Laravel, you can remove the global scope from a relation by using the withoutGlobalScope()
method. This method allows you to remove a global scope from a specific query.
Here's an example of how to remove a global scope from a relation:
php$user = User::withoutGlobalScope('active')->find(1);
$posts = $user->posts()->withoutGlobalScope('published')->get();
In this example, we have a User
model with a posts
relation. We want to remove the active
global scope from the user, and the published
global scope from the user's posts.
The withoutGlobalScope()
method takes the name of the global scope as its argument. So, we can use it to remove the global scopes we want to exclude.
By using the withoutGlobalScope()
method, we can modify a specific query to exclude certain global scopes, while leaving them intact for other queries.
Comments
Post a Comment