I have a project that uses 6 different databases, most of all my important data is in a database different from the main Laravel database that I called "core". However my main User database is in the main "core" database, almost everything else is in a 'data' database.
Using this setup I am able to use Laravel Love without a hitch so far.. I can add/remove reactions and all the tables and counts are working correctly.
My main use of Laravel Love is that users can like other users. Very simple.
Today I tried to do this:
$users = User::with('profile')->whereReactedBy($user, 'Like')->get();
And I ran into this error:
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'core.love_reactants' doesn't exist (SQL: select * from `core`.`users` where exists (select * from `love_reactants` where `core`.`users`.`love_reactant_id` = `love_reactants`.`id` and exists (select * from `love_reactions` where `love_reactants`.`id` = `love_reactions`.`reactant_id` and `reacter_id` = 6176 and `reaction_type_id` = 1)) and `core`.`users`.`deleted_at` is null) in file /Volumes/Memories/Photos/2012/PictureBright/DEV/_NS/2020/omega-api.nomadsoulmates.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 671
I've run into such issues with other relations cross-database and usually the fix is as simple as going inside the model file and prefixing the table with the database name
So something like this:
class Comment extends Model
protected $table = 'data.matches';
The problem is I can't do this with the Love models since they are in your codebase. I haven't tried binding my own models in place of yours so I can add this one extra line.
I did define in the love.php configuration file that it should use my database connection and things have worked so far. I guess this would work if you also prefixed the database name to the definition of your tables in your vendor models when the user specifies a custom database connection.
If you have another solution to offer I would love to hear it.
Thank you very much!