Я хочу отправить уведомление многим пользователям в одно и то же время, но laravel создать только уведомление для первого пользователя, и когда я пытаюсь сделать это с другим пользователем, у меня возникла проблема с дублированием первичного ключа
local.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5' for key 'PRIMARY' (SQL: insert into `notifications` (`id`, `type`, `data`, `read_at`, `notifiable_id`, `notifiable_type`, `updated_at`, `created_at`) values (5, App\Notifications\NewProject, {"id":5,"nom":"base de donnes"}, ?, 4, App\User, 2020-04-01 17:58:24, 2020-04-01 17:58:24)) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5' for key 'PRIMARY' (SQL: insert into `notifications` (`id`, `type`, `data`, `read_at`, `notifiable_id`, `notifiable_type`, `updated_at`, `created_at`) values (5, App\\Notifications\\NewProject, {\"id\":5,\"nom\":\"base de donnes\"}, ?, 4, App\\User, 2020-04-01 17:58:24, 2020-04-01 17:58:24)) at C:\\xampp\\htdocs\\gestion\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:669)
[stacktrace]
а это мой код в контроллере
public function store(Request $request)
{
$data = $request->all();
$projet = Projet::latest()->orderBy('created_at','DESC')->first();
foreach($request->membre_id as $id_mem){
$membre = User::where('id' , $id_mem)->first();
$userprojet = new ProjetUser;
$userprojet->user_id = $id_mem;
$userprojet->membre = $membre->name;
$userprojet->role=$membre->role;
$userprojet->projet_id = $projet->id;
$userprojet->save();
$membre->notify(new NewProject ($projet->id,$projet->name));
}
}
public function storeChef(Request $request){
$projet = Projet::latest()->orderBy('created_at','DESC')->first();
$chef = User::where('id' , $request->chefprojet)->first();
$userprojet = new ProjetUser;
$userprojet->user_id = $chef->id;
$userprojet->membre = $chef->name;
$userprojet->role=$chef->role;
$userprojet->projet_id = $projet->id;
$userprojet->save();
$chef->notify(new NewProject ($projet->id,$projet->name));
}