Level 75
Everything what you need you have in the documentation
https://laravel.com/docs/8.x/eloquent-relationships#updating-many-to-many-relationships
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i want to update roles on my admin panel. But I don't discover the way.
role_Pivot Table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRoleUserTable extends Migration
{
public function up()
{
Schema::create('role_user', function (Blueprint $table) {
$table->foreignId('role_id')->references('id')->on('roles')->cascadeOnDelete();
$table->foreignId('user_id')->references('id')->on('users')->cascadeOnDelete();
});
}
public function down()
{
Schema::dropIfExists('role_user');
}
}
Controller
public function update(Request $request, User $user) {
$user->update([
'status' => $request->status
'role' =>
]);
return redirect()->route('admin.team')->with('success','Team status Updated Successfully');
}
Please or to participate in this conversation.