Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Heimdall's avatar

connect table

Hello

I have table Evenement, and i want update this table on my controller :



    public function destroy(Participant $participant, ParticipantbyEvent $ParticipantbyEvent, Evenement $event)
    {

	.....

        $idevent = $participant->evenement_id;

            if ($goodnbrplace === "illimité")
         {
            $event -> nbrPlace = "illimité";
            $event  -> update(array('id' => $idevent));
         }


         if ($goodnbrplace != "illimité")
         {
           $goodnbrplacenoillimite = $goodnbrplace + 1;
           $event -> nbrPlace = $goodnbrplacenoillimite;
           $event  -> update(array('id' => $idevent));
         }



     return redirect('/eventsub');
    }

But idk why, when i try dd($event) i have no connection on my table Evenement...

Ty

0 likes
4 replies
Snapey's avatar

You are not using update correctly.

Update will only change the fields that you specify in the braces.

If you want to set the nbrPlace field then you should use save()

           $event->nbrPlace = $goodnbrplace + 1;
           $event->save();

(also, remove pointless temporary variables)

Heimdall's avatar

I need to use method update if i want update my table no ?

i change my code like this :


        $idevent = $participant->evenement_id;


   $events = Evenement::where('id', $idevent) ->get();
       $goodnbrplace = $events[0] -> nbrPlace;

            if ($goodnbrplace === "illimité")
         {
            $events -> nbrPlace = "illimité";
            $events  -> update();
         }


         if ($goodnbrplace != "illimité")
         {
           $goodnbrplacenoillimite = $goodnbrplace + 1;
           $events -> nbrPlace = $goodnbrplacenoillimite;
           $events  -> update();
         }


But i have this error now :

Method Illuminate\Database\Eloquent\Collection::save does not exist.

Heimdall's avatar
Heimdall
OP
Best Answer
Level 1

ok that work i remplace -> get by -> first

Snapey's avatar

update is for use where you don't have the model, but have the ID and the new data

Please mark answered if your problem is resolved

Please or to participate in this conversation.