Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Do you have a '<mytable>' table on '<myconnect>' database?. Also, have you configured the '<myconnection>' connection?

Last updated 2 years ago.
0

Yes, table works in own model.

This echo -line, try find this Customers table from <default connection>'s database, not <myconnection>'s database. Why?

Last updated 2 years ago.
0

Im guessing that the customer data is being held on a different database to the reservations?

If that's so then you can try specifying the connection for that model explicity in the class. So in your Customer class, add this:

protected $connection = 'mysql';

make sure the connection name is correct according to your database configuration, then laravel should select customers using the correct connection.

I haven't tried this myself, but it should work i think :/

Last updated 2 years ago.
0

Tables Reservations and Customers are at same database. I can't define protected $connection because, connection is different at different cases.

Last updated 2 years ago.
0

Have you tried with setConnection ?

Last updated 2 years ago.
0

Ruk33 said:

Have you tried with setConnection ?

Same problem

Last updated 2 years ago.
0

More Infomartion:

var_dump($res);
  • Result:
["connection":protected]=> string(8) "myconnect"

BUT

var_dump($res->customer);
  • Result:
["connection":protected]=> NULL

So if I use customer method in reservations model, connection is NULL and Laravel connect with default connection, not <myconnection> what I defined.

Is this bug or my dumbness?

Last updated 2 years ago.
0

If somebody resolve this, I will pay 20$ with Paypal :)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

0lide 0lide Joined 13 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.