Support the ongoing development of Laravel.io →
Database Eloquent

I am currently trying to insert the value of fields to a table. However, this error keeps coming up:

ksort() expects parameter to be array, integer given

Here is the code in my controller:

public function store(Request $request)
    {
        $input = $request->all();
        $businessfunction = BusinessFunction::create($input);

        $fields = Input::get('fields_');

        foreach($fields as $field) {
            DB::table('field_instances')->insert(
                ['value' => $fields, 'businessfunction_id' => $businessfunction->id]
            );
        }

I thought putting the information in a foreach loop would fix it, but I'm still getting the same error. Any assistance would be appreciated!

Last updated 3 years ago.
0

here i think it should be $field ?

['value' => $field, 'businessfunction_id' => $businessfunction->id]
0

astroanu said:

here i think it should be $field ?

['value' => $field, 'businessfunction_id' => $businessfunction->id]

Even when I use 'field' it doesn't work. It gives me the same error.

0

To diagnose this do this

['value' => json_encode($field), 'businessfunction_id' => $businessfunction->id]

and see what is got inserted in db.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.