Aronaman
2 months ago
203
5
Laravel

sync many to many

Posted 2 months ago by Aronaman

hello guys

room parent has 5 room child. quantity count the room child show in front end. my question is if the customer choice quantity b/n 1 to 5 . let say the customer choice 3 and book the room. the first 3 room children save in pavot table of booking_Individual. how can i do this??

room(parent)->individualRoom(child) 1 to many relationship

$result=$room()->individiual_rooms_count()->get();

<div class="form-group">
            <strong>Quantity:</strong>
    

              <select  name="quantity" >   
                  @for($i=1; $i<=$result; $i++)  
                  <option  >{{$i}}</option>
                  @endfor
              </select>

    
        </div>

booking.php //model


    public function individualRooms()

    {
      return $this->belongsToMany(individualRoom::class,'booking__individualroom');
    }

storeBooking

$booking =$room->bookings()->create($booking);
 $booking->individualRooms()->sync([???]));

if the user select 2 quantity the store the first 2 individual room, if 3 quantity selected same the first 3 from the individualroom .....

Please sign in or create an account to participate in this conversation.