2021年4月8日星期四

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".

Thanks.

https://stackoverflow.com/questions/67015140/laravel-eloquent-model-with-relationship April 09, 2021 at 12:39PM

没有评论:

发表评论