Reactant not exists.
Marchiuzzz opened this issue · comments
Hi, I have followed the setup guidelines to get this package installed for my existing project with already existing models and records. However, I ran into a problem I cannot seem to solve. Whenever I try to use "$reacterFacade->reactTo" I get this "Reactant not exists." error, I have registered reacterers as well as reactants manually, as suggested in #105 , but that did not solve the issue. Here's my simple function
public function like(Request $request){
if(Auth::check()){
$user = Auth::user();
$object = DynamicAbstractObject::where('unique_entity_id', $request->input('entity'))->first();
if(!empty($object)){
if($object->isNotRegisteredAsLoveReactant()){
$object->registerAsLoveReactant();
$object->save();
}
if($user->isNotRegisteredAsLoveReacter()){
$user->registerAsLoveReacter();
$user->save();
}
$reacterFacade = $user->viaLoveReacter();
$reacterFacade->reactTo($object, 'Like', 4.0);
}
}
}
Any help would be much appreciated
Do you have records in love_reactants
database table? There is no need to create reactants on the fly on each like
call. It should be done once for each model on initial package integration: https://laravel-love.readme.io/v8/docs/restore-missing-reactants
I found what the problem was. I ignored the fact that when executing this step of setup "php artisan love:setup-reactable --model="App\Comment" I ran the migration and the column was created but foreign key failed to create. All I had to do was run "php artisan love:setup-reactable --model="App\Comment --nullable" instead and then repeat the manual registration. Everything works now, thanks for this wonderful package.