cupcaved
2 months ago
144
4
Laravel

Laravel one to one relationship

Posted 2 months ago by cupcaved

Hi guys I am new in Laravel I want your help. Here is my database:

user: id, name, surname, email, role

user_informations: id, user_id, status I want the name of all users where status is enable.

What I do is this:

User.php

public function information()
    {
        return $this->hasOne('App\UserInformation');
    }

UserInformation.php

 public function guider()
    {
        return $this->belongsTo('App\User');
    }

This is my query:

 $users =User::where('role', '2')->information()->get();

Call to undefined method Illuminate\Database\Eloquent\Builder::information()

I know my query is wrong, because i ahve not defined anywhere that i want to get all users that have their status 'enable'

Please sign in or create an account to participate in this conversation.