-
I'm trying to make Dependency Injection of a serviceclass to use its methods to do something in the bulk actions. When using mount() it simply tells: When using boot() to resolve the previous error I get the following: Using boot is what I usually use with Livewire to make DI to work. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
So you're trying to make use of your userService somewhere in the Bulk Actions? There's a couple of options here, if you let me know where exactly you're making a call to it, and I can give you a steer as to where to add it in! Drop what you're doing with your boot method to help me out a bit. The best method in my opinion? Create a trait for your UserService, and then use the Livewire Lifecycle bindings to load it properly. You can of course just call the parent method at the end of your customised boot method within the component itself, but note that this approach isn't entirely recommended, and you may have some oddities, so it's best practice to use Traits, especially where you're going to end up re-using the code! If you wanted to just proceed with a custom boot method, then this would work:
Otherwise, you could have a trait (e.g. UserServiceTrait), and call the following in your trait: public function bootUserServiceTrait
{
// Your Code Here
} mountUserServiceTrait will also work there. |
Beta Was this translation helpful? Give feedback.
-
Editor's note: Sorry about the confusion, the answer deleted was to another issue. Below comes the real answer to @lrljoeThe original code giving the "(...) must be compatible with Rappasoft (...)" is as follows.
The solution I found to make it work was simply giving up on using the service, eliminating bool() at all and repeat the query using Eloquent directly on the bulk action's methods.
P.S. - I tried calling parent::bool() in the end and the error keeps there. |
Beta Was this translation helpful? Give feedback.
Alright, finally I've found a solution to my problem!
To finally solve the "xxxService must not be accessed before initialization" and rightfully use my services I did this:
then I call it on builder():
Now I can use the services I injected…