While converting my old tests to the new Factory class, I'm unable to find how to reproduce the afterCreatingState function.
I tried the following:
public function admin() {
$this->afterCreating(function (User $user) {
$user->admin_user()->save(new AdminUser);
}
return $this->state([]);
}
but the afterCreating callback never fires. I don't know where else to put the block. Is this an oversight or am I missing something?
Read the docs a little more thoroughly, I missed that the callback must be returned:
public function admin() {
return $this->afterCreating(function (User $user) {
$user->admin_user()->save(new AdminUser);
});
}
Read the docs a little more thoroughly, I missed that the callback must be returned:
public function admin() { return $this->afterCreating(function (User $user) { $user->admin_user()->save(new AdminUser); } }
You are missing ); at the fourth line but thanks anyway, it solved my problem :)
@jdavidbakr and if you want to compose multiple states on afterCreating ? More like "nested relationship multiple state".
@robsontenorio I'm not sure I understand what you are asking me?
Most helpful comment
Read the docs a little more thoroughly, I missed that the callback must be returned: