amoktar's avatar

How can I load non-related model as relationship ?

Hello all. I have a User and Lesson models. these models are not related to each other.

users table: id, username, password, is_active lessons table: id, title

User
class User extends Modle
{
    // code 
}

Lesson
class Lessosn extends Modle
{
    public function users()
    {
        // I need to return all users here where is_active=true as RELATIONSHIP
        // return User::where('is_active', true);
    }
}

In the Lesson model I want to have a relationship to load users where (is_active, true) So I can list all users where is_active = true

Thanks

0 likes
5 replies
tykus's avatar

If there is no relationship; why is the Lesson model responsible for loading User instances? What problem are you actually trying to solve here?

amoktar's avatar

@tykus I'm trying to define the relation although there is no relation between the two models because I want to use this relation in filamentphp relationship manager

tykus's avatar

@amoktar okay? Why should there be a list of active users displaying along with a Lesson; what does the user infer from this? If we better understand your requirements, we can suggest alternative approaches.

amoktar's avatar

@tykus thanks for trying to help the list of users is like candidates to have a relationship

martinbean's avatar

these models are not related to each other.

@amoktar Then fix that.

The models clearly are related to each other, so define the appropriate relations in your models.

Please or to participate in this conversation.