not sure where roles fit in, but I assume
$state->reps()->get();
would return up to 3 users? each having a different role?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Some background Laravel 10.x mysql db Spatie Roles and permissions
so what i have is a many to many (states to representatives) there is 3 rep types at this point, with each type being its own role.
States table
public function reps()
{
return $this->belongsToMany(User::class);
}
User table
public function repStates()
{
return $this->belongsToMany(State::class);
}
State_rep
Schema::create('state_user', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained();
$table->foreignId('state_id')->constrained();
$table->timestamps();
});
what i want is to say something like this
$state->regionalSalesRep();
$state->insideSalesRep()
$state->customerService()
currently i have states - reps - user - roles - user - roles - user - roles
I need to find a way to do this efficiently do im not sending out 180 queries per page load.
Please or to participate in this conversation.