{"action":"created","issue":{"url":"https://api.github.com/repos/HipsterJazzbo/Landlord/issues/52","repository_url":"https://api.github.com/repos/HipsterJazzbo/Landlord","labels_url":"https://api.github.com/repos/HipsterJazzbo/Landlord/issues/52/labels{/name}","comments_url":"https://api.github.com/repos/HipsterJazzbo/Landlord/issues/52/comments","events_url":"https://api.github.com/repos/HipsterJazzbo/Landlord/issues/52/events","html_url":"https://github.com/HipsterJazzbo/Landlord/issues/52","id":197335427,"number":52,"title":"Modify tenant id in after middleware?","user":{"login":"inctor","id":1939469,"avatar_url":"https://avatars.githubusercontent.com/u/1939469?v=3","gravatar_id":"","url":"https://api.github.com/users/inctor","html_url":"https://github.com/inctor","followers_url":"https://api.github.com/users/inctor/followers","following_url":"https://api.github.com/users/inctor/following{/other_user}","gists_url":"https://api.github.com/users/inctor/gists{/gist_id}","starred_url":"https://api.github.com/users/inctor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inctor/subscriptions","organizations_url":"https://api.github.com/users/inctor/orgs","repos_url":"https://api.github.com/users/inctor/repos","events_url":"https://api.github.com/users/inctor/events{/privacy}","received_events_url":"https://api.github.com/users/inctor/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-23T09:13:17Z","updated_at":"2016-12-28T11:49:31Z","closed_at":"2016-12-28T11:49:31Z","body":"Hey,\r\n\r\nIt seems like it's not possible to modify the Tenant ID after it's been set once.\r\n\r\nCurrently we're setting in a Scope Middleware, that's globally applied, and it works perfectly.\r\n\r\nBut we have a few instances where we'd like to change/modify the Tenant ID to be something else, if we need to run artisan commands or other console related commands.\r\n\r\nThis is what i've tested with:\r\n\r\n`\\DB::enableQueryLog();\r\n   \r\n        User::whereActivated(1)->get();\r\n        $this->info(json_encode(\\Landlord::getTenants()));\r\n\r\n        \r\n        \\Landlord::disable();\r\n        User::whereActivated(1)->get();\r\n        $this->info(json_encode(\\Landlord::getTenants()));\r\n        \r\n        \r\n        \\Landlord::removeTenant('company_id');\r\n        User::whereActivated(1)->get();\r\n        $this->info(json_encode(\\Landlord::getTenants()));\r\n        \r\n        \r\n        \\Landlord::addTenant('company_id',123);\r\n        User::whereActivated(1)->get();\r\n        $this->info(json_encode(\\Landlord::getTenants()));\r\n        \r\n        \\Landlord::addTenant('company_id',123);\r\n        User::allTenants()->whereActivated(1)->get();\r\n        $this->info(json_encode(\\Landlord::getTenants()));\r\n        \r\n        dd( \\DB::getQueryLog() );`\r\n\r\nAnd this is the response i'm getting:\r\n\r\n> {\"company_id\":71}\r\n> {\"company_id\":71}\r\n> []\r\n> {\"company_id\":123}\r\n> {\"company_id\":123}\r\n> array:5 [\r\n>   0 => array:3 [\r\n>     \"query\" => \"select * from `users` where `activated` = ? and `users`.`company_id` = ? and `users`.`deleted_at` is null\"\r\n>     \"bindings\" => array:2 [\r\n>       0 => 1\r\n>       1 => 71\r\n>     ]\r\n>     \"time\" => 0.72\r\n>   ]\r\n>   1 => array:3 [\r\n>     \"query\" => \"select * from `users` where `activated` = ? and `users`.`company_id` = ? and `users`.`deleted_at` is null\"\r\n>     \"bindings\" => array:2 [\r\n>       0 => 1\r\n>       1 => 71\r\n>     ]\r\n>     \"time\" => 0.82\r\n>   ]\r\n>   2 => array:3 [\r\n>     \"query\" => \"select * from `users` where `activated` = ? and `users`.`company_id` = ? and `users`.`deleted_at` is null\"\r\n>     \"bindings\" => array:2 [\r\n>       0 => 1\r\n>       1 => 71\r\n>     ]\r\n>     \"time\" => 0.44\r\n>   ]\r\n>   3 => array:3 [\r\n>     \"query\" => \"select * from `users` where `activated` = ? and `users`.`company_id` = ? and `users`.`deleted_at` is null\"\r\n>     \"bindings\" => array:2 [\r\n>       0 => 1\r\n>       1 => 71\r\n>     ]\r\n>     \"time\" => 0.49\r\n>   ]\r\n>   4 => array:3 [\r\n>     \"query\" => \"select * from `users` where `activated` = ? and `users`.`deleted_at` is null\"\r\n>     \"bindings\" => array:1 [\r\n>       0 => 1\r\n>     ]\r\n>     \"time\" => 0.42\r\n>   ]\r\n> ]\r\n\r\n\r\nAs seen, the Tenant ID is the same for all of them, except after i've called \"allTenants()\", it correctly removed the tenant-scope, but that's not what i want to achieve.\r\n\r\nIs this an issue with this package, or something deeper in Eloquent's way of handling the global scopes?\r\n\r\nIn addition to this, Disable() does not seem to make any difference at all either."},"comment":{"url":"https://api.github.com/repos/HipsterJazzbo/Landlord/issues/comments/269466788","html_url":"https://github.com/HipsterJazzbo/Landlord/issues/52#issuecomment-269466788","issue_url":"https://api.github.com/repos/HipsterJazzbo/Landlord/issues/52","id":269466788,"user":{"login":"inctor","id":1939469,"avatar_url":"https://avatars.githubusercontent.com/u/1939469?v=3","gravatar_id":"","url":"https://api.github.com/users/inctor","html_url":"https://github.com/inctor","followers_url":"https://api.github.com/users/inctor/followers","following_url":"https://api.github.com/users/inctor/following{/other_user}","gists_url":"https://api.github.com/users/inctor/gists{/gist_id}","starred_url":"https://api.github.com/users/inctor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inctor/subscriptions","organizations_url":"https://api.github.com/users/inctor/orgs","repos_url":"https://api.github.com/users/inctor/repos","events_url":"https://api.github.com/users/inctor/events{/privacy}","received_events_url":"https://api.github.com/users/inctor/received_events","type":"User","site_admin":false},"created_at":"2016-12-28T11:49:31Z","updated_at":"2016-12-28T11:49:31Z","body":"In regards to this issue, the problem still exists, but we've worked around it, and went through our callstack, and made certain nothing can get booted before it's needed and the middleware scope has run.\r\n\r\nAlso had to implement the change from this PR to fix the other issue.\r\nhttps://github.com/HipsterJazzbo/Landlord/pull/53"}}
{"actor":{"display_login":"inctor"}}