cb2004 Posted May 9, 2016 Share Posted May 9, 2016 I am building a system which has a page selector using the template user. When the page is added I wish to autopopulate the page_user field with the logged in user, but they can also change this should they wish. This doesnt seem to work: $pages->addHookAfter("added", function($event) { $page = $event->arguments(0); if ($page->template->id == 57) { $page->setAndSave("page_user", $user); } } I have also tried numerous other things like $page->page_user = $user, and lots of variations but no joy. What does actually work is something like $page->setAndSave("page_user", 41); so its not reading the logged in $user, even if I do something like $user->id. Any help would be appreciated. Cheers. Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 9, 2016 Share Posted May 9, 2016 The function is a closure, which does have it's own variable scope, so local variables like $page or $user are not populated. You'd need to use one of those: wire('user') $this->user $event->user 1 Link to comment Share on other sites More sharing options...
cb2004 Posted May 9, 2016 Author Share Posted May 9, 2016 Thanks as always LostKobrakai, went with $this->user. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now