{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/9696","labels_url":"https://api.github.com/repos/laravel/framework/issues/9696/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/9696/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/9696/events","html_url":"https://github.com/laravel/framework/pull/9696","id":96183671,"number":9696,"title":"[5.1] Prevent reapplying scopes in whereHas callback","user":{"login":"jarektkaczyk","id":6928818,"avatar_url":"https://avatars.githubusercontent.com/u/6928818?v=3","gravatar_id":"","url":"https://api.github.com/users/jarektkaczyk","html_url":"https://github.com/jarektkaczyk","followers_url":"https://api.github.com/users/jarektkaczyk/followers","following_url":"https://api.github.com/users/jarektkaczyk/following{/other_user}","gists_url":"https://api.github.com/users/jarektkaczyk/gists{/gist_id}","starred_url":"https://api.github.com/users/jarektkaczyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarektkaczyk/subscriptions","organizations_url":"https://api.github.com/users/jarektkaczyk/orgs","repos_url":"https://api.github.com/users/jarektkaczyk/repos","events_url":"https://api.github.com/users/jarektkaczyk/events{/privacy}","received_events_url":"https://api.github.com/users/jarektkaczyk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/laravel/framework/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/laravel/framework/labels/database","name":"database","color":"eb6420"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-20T23:02:41Z","updated_at":"2015-07-30T15:24:07Z","closed_at":"2015-07-30T15:24:07Z","pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/9696","html_url":"https://github.com/laravel/framework/pull/9696","diff_url":"https://github.com/laravel/framework/pull/9696.diff","patch_url":"https://github.com/laravel/framework/pull/9696.patch"},"body":"This fixes the problem of reapplying global scopes constraints if you try to remove them in the `whereHas` callback - take `SoftDeletes` as an example:\r\n\r\n```php\r\n// Basic has call - 'deleted_at is null' applied by default\r\n>>> User::has('posts')->toSql()\r\n=> \"select * from `users` where (select count(*) from `posts` where `posts`.`user_id` = `users`.`id` and `posts`.`deleted_at` is null) >= 1\"\r\n\r\n// Now let's remove the 'deleted_at is null' constraint in the callback\r\n>>> User::whereHas('posts', function ($q) { $q->withTrashed(); })->toSql()\r\n=> \"select * from `users` where (select count(*) from `posts` where `posts`.`user_id` = `users`.`id` \r\n\r\nand `posts`.`deleted_at` is null // SOFT DELETE CONSTRAINT SHOULDN'T BE HERE ANYMORE\r\n\r\n) >= 1\"\r\n>>> \r\n```\r\n\r\nThis happens because `mergeWheresToHas` is applied **after** user-provided callback."},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/126369448","html_url":"https://github.com/laravel/framework/pull/9696#issuecomment-126369448","issue_url":"https://api.github.com/repos/laravel/framework/issues/9696","id":126369448,"user":{"login":"taylorotwell","id":463230,"avatar_url":"https://avatars.githubusercontent.com/u/463230?v=3","gravatar_id":"","url":"https://api.github.com/users/taylorotwell","html_url":"https://github.com/taylorotwell","followers_url":"https://api.github.com/users/taylorotwell/followers","following_url":"https://api.github.com/users/taylorotwell/following{/other_user}","gists_url":"https://api.github.com/users/taylorotwell/gists{/gist_id}","starred_url":"https://api.github.com/users/taylorotwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taylorotwell/subscriptions","organizations_url":"https://api.github.com/users/taylorotwell/orgs","repos_url":"https://api.github.com/users/taylorotwell/repos","events_url":"https://api.github.com/users/taylorotwell/events{/privacy}","received_events_url":"https://api.github.com/users/taylorotwell/received_events","type":"User","site_admin":false},"created_at":"2015-07-30T15:24:07Z","updated_at":"2015-07-30T15:24:07Z","body":"Closing pending inactivity."}}