Alex Gk
Alex Gk

Reputation: 47

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value:

I have a problem only when updating (not creating) I got this error :

Illuminate\Database\QueryException SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'on' for column alleshops.eshops.payathome at row 1 (SQL: update eshops set payathome = on, paywithcard = on, eshops.updated_at = 2021-01-17 05:33:03 where id = 10)

Here is my controller:

public function edit_eshop(Eshop $eshop,Request $request){
    if ($request->method() == 'POST'){                       
        $eshop->title = $request->get('title');
        $eshop->link = $request->get('link');
        $eshop->telephone = $request->get('telephone');
        $eshop->email = $request->get('email');
        $eshop->payathome = $request->get('payathome');
        $eshop->paywithcard = $request->get('paywithcard');
        $eshop->tags = $request->get('tags');
        if($eshop->save()){
            echo "Το eshop δημιουργήθηκε επιτυχώς.";
            return redirect('/eshops');
        };
    };        
    return view('edit_eshop', ['eshop' => $eshop]);
}

similar questions didn't help me unfortunatelly

Upvotes: 0

Views: 1366

Answers (1)

starlight93
starlight93

Reputation: 136

I suggest you to use dd($request->all()) to visualize the user's request payload.

Based on your problem, I think the problem is in $request->get('payathome'). It is not an integer value, I don't care about the input field, but it tells us that payathome data is a string. Try to convert it, just like: $eshop->payathome = $request->get('payathome')=="on"?1:0;

Hope this help you. Happy Code!

Upvotes: 3

Related Questions