Referring to this ( http://laravel.io/forum/06-29-2014-custom-pivot-table-that-accepts-null-values-using-attach-does-not-work-with-null-values-why-how-to-work-around ) problem, you can pass null only in square brackets.
So the solution is
$user=App\User::first();
$role=App\Role::first();
$user->website()->attach([null], array('role_id' => $role->id));
It actually works.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community