-
https://github.com/luadotsh/lua/blob/main/app/Models/Traits/HasWorkspaces.php
Open in GitHubuse App\Models\Workspace; trait HasWorkspaces { public function workspaces() { return $this->belongsToMany(Workspace::class) ->withPivot('role') ->wherePivotNotNull('role') ->as('membership') ->withTimestamps(); } // ... }
-
app/Http/Controllers/Setting/TeamMemberController.php
Open in GitHubuse App\Http\Requests\TeamMember\UpdateUserRoleRequest; use Illuminate\Database\Eloquent\Builder; use App\Models\User; class TeamMemberController extends Controller { // ... public function updateUserRole($id, UpdateUserRoleRequest $request) { $user = User::where('id', $id) ->whereHas('workspaces', function (Builder $query) { $query->where('workspaces.id', auth()->user()->currentWorkspace->id); }) ->firstOrFail(); $user->workspaces()->syncWithPivotValues([auth()->user()->currentWorkspace->id], ['role' => $request->role], false); session()->flash('flash.banner', 'User role updated'); session()->flash('flash.bannerStyle', 'success'); return back(); } // ... }