lundi 16 novembre 2020

Relation query undefined method

In my setting model class i have this

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

and in my user model class i have this

 public function settings()
    {
        return $this->belongsTo('App\settings', 'id');
    }

I tried both these queries, trying to get the user information but failed.

$data = DB::table('settings')
                        ->where('id', '=', $id)
                        ->get()
                        ->toArray();

and

$table = \App\settings::where('id', '=', $id);
        $query = $table->user()
                       ->get()
                       ->toArray();

I'm getting this error

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

How do you do relation query? Sorry new to laravel here.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire