I have tables: users, resources and pivot table user_resources.
users
- id
- username
etc.
resources
- id
- resource_name
etc.
user_resources
- id
- user_id
- resource_id
User model:
class Resources extends Eloquent {
public function users() {
return $this->belongsToMany('User', 'user_resources');
}
}
and resource model:
class User extends Eloquent {
public function resources() {
return $this->belongsToMany('Resource', 'user_resources');
}
}
How can I get all of the users and all of the resources that belongs to the users.