Laravel Eloquent Model with relationship

I have implemented eloquent relationship in my code but Laravel unable to read the function that I created to map the eloquent relationship in the model.

User Model

public function products(){
        return $this->hasMany(Product::class,'userid');

Product Model

public function users(){
        return $this->belongsTo(User::class);

Product Controller

 $products = Product::with('Users')->Users()->where('users.isActive',1)->get();
        return view('product',compact('products'));

I keep getting error from the product controller, I also attached the error that I current encountered as below. enter image description here

How can I get all the product and user data with the where condition such as "Users.isActive = 1".


Read more here:

Content Attribution

This content was originally published by Miracle Hades at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: