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

hjortur17's avatar

How to add services to booking in database

I'm not sure what Eloquent connect I should use. Should I put on Booking hasMany()? I like to have it like this: The user can not add a service, he can click checkboxes and select service and then that will be connected to the Booking.

0 likes
7 replies
hjortur17's avatar

Okay, so are you saying that the line in my store function should look something like this:

$booking->services()->create([request('services')]);
hjortur17's avatar

And how should my input look like? I'm using Vue JS for posting to the server and it looks like this right now:

<input class="mr-2 leading-tight" type="checkbox" :value="17900" v-model="services">
aurawindsurfing's avatar

You are posting to an endpoint, you should handle that in your controller.

1 like
hjortur17's avatar

I know, I'm just not sure how to do this. For example if I have three services and the user checks 1 and 3 how do I add that to the database using this createMany method?

hjortur17's avatar
hjortur17
OP
Best Answer
Level 14

This solved it:

$booking->services()->attach($request->services)

Please or to participate in this conversation.