2 months ago

Filter by attribute from pivot table

Posted 2 months ago by mleontenko

I have the following method in my model that retrieves all the related users and their roles:

public function operators()
        return $this->belongsToMany('App\User', 'obrasciOperateriUloge', 'id_obrasca', 'id_operatera')->withPivot('role');        

The results look like this:

      "email":"[email protected]",
      "created_at":"2020-03-09 11:26:16",
      "updated_at":"2020-03-09 11:26:16",

I want to add an aditional filter in operators() method that returns only the users with role "Author". How can I do this?

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