Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

luadotsh/lua

324 stars
2 code files
View luadotsh/lua on GitHub

https://github.com/luadotsh/lua/blob/main/app/Models/Traits/HasWorkspaces.php

Open in GitHub
use 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 GitHub
use 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();
}
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.