Let's say i have this DB structure:
Table A:
-id
-user_id
Table B:
-id
-user_id
Table C:
-id
-user_id
Users:
-id
This is my User Model
namespace App\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $table = 'users';
protected $fillable = ['name','email','username','password'];
/**
* Relationships
*/
public function tableA()
{
return $this->hasOne(\App\Models\TableA::class);
}
public function tableB()
{
return $this->hasOne(\App\Models\TableB::class);
}
public function tableC()
{
return $this->hasOne(\App\Models\TableC::class);
}
public function tableD()
{
return $this->hasOne(\App\Models\TableD::class);
}
}
This is what i want to achieve:
public function tables()
{
// return all records from all 3 tables (Table A, Table B, Table C)
}
The way I can get a certain information on a table is by defining a relationship within the User model, saying it hasOne record of TableA, TableB, etc. However, I'm searching for a way to find on which of these tables (a,b,c,d) there is a Fk of User, following the same concept of relationships.
Note: Polymorphism is not a solution in this case