nionta
118
5
Mix

data is not saving in database

Posted 6 months ago by nionta

this is my controller file :

public function postdata(Request $request)
    {
    $month_year_multi_ids = $request->get('checkbox_Names');
    $company = $request->get('company');


    foreach ($month_year_multi_ids as $key => $value) {
        $last_space = strrpos($value, ' ');
        $year[] = substr($value, $last_space);
        $month[] = substr($value, 0, $last_space);
    }

    $validation = $request->validate([

        'company' => 'required',
        'checkbox_Names' => 'required',

    ]);

    $error_array = array();
    $success_output = '';


    if ($request->get('button_action') == "insert")
    {
        foreach ($month_year_multi_ids as $index => $values) {
            $company_year = new CompanyYear([

                'company_id'  => $company,
                'year' => $year[$index],
                'month' => $month[$index],

            ]);
            $company_year->save();
        }

    }
    $success_output = '<div class="alert alert-success">Data Inserted</div>';

    $output = array(
        'errror' => $error_array,
        'success' => $success_output
    );
    echo json_encode($output);

}

data is showing success , but data is not saving in database. also $company, $year and $month variable is showing the right value. where is the problem? why the data is not saving?

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

Reply to

Use Markdown with GitHub-flavored code blocks.