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

ruben777's avatar

post checkboxes value

I am building a form to add one or multiple checkers to a website, using Laravel, Inertia vue.js. I have a table with three columns : id, website_id, checker_id.

here is my form :

<form @submit.prevent="store">
	<div v-for="checker in checkers" :key="checker.id">
		<input type="checkbox" :id="checker.id" :value="checker.id" v-model="checked">
		<label :for="checker.id">{{checker.name}}</label>
	</div>
	<button type="submit">Save</button>
</form>
data() {
    return {
        checked: []
    }
}
store() {
    axios.post('/submit', this.checked)
}

console.log(this.checked) returns this :

Proxy { : (1) […], : {…} } ​ : Array [ id, id ]

0: id 1: id length: 2

for the moment my controller looks like this :

public function store()
    {

        WebsiteCheckers::create([
            'checker_id' => request('checked'),
            'website_id' => ?
        ]);
    }

I have absolutly no idea on how to persist the data in DB neither how to make my controller. any help will be much appreciated !

0 likes
5 replies
tykus's avatar
tykus
Best Answer
Level 104

First, send an appropriate payload (an Object):

store() {
    axios.post('/submit', {checked: this.checked})
}

Now, since you are getting an array of data then iterate:

public function store()
{
    foreach(request('checked', []) as $checkerId) {
        WebsiteCheckers::create([
            'checker_id' => $checkerId
            'website_id' => ?
        ]);
    }
}

I don't see a website_id either in the Request or URL, so I don't know where you intend to get this data? Is it available in the Vue app?

ruben777's avatar

@tykus thank you for your reply. I did what you told me and now I have a 500 error. Also, website_id is available in my Vue component.

tykus's avatar

@ruben777 you need to pass the website_id to the Laravel application:

store() {
  axios.post('/submit', {
    checked: this.checked,
    website_id: this.website_id
  })
}
public function store()
{
    foreach(request('checked', []) as $checkerId) {
        WebsiteCheckers::create([
            'checker_id' => $checkerId,
            'website_id' => request('website_id'),
        ]);
    }
}

Check your logs for the cause of the 500.

ruben777's avatar

@tykus it worked well. website_id is only available in this.websites data but I will find a way. thank you very much for your answers

1 like

Please or to participate in this conversation.