1
votes

Actually I was making a blog with Laravel following a Youtube tutorial (Laravel 5.5). I was adding profile page there was "Name, Designation, Profile pic". I got error as "Invalid datetime format:1366".

Illuminate \ Database \ QueryException (22007)
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '{"id":1,"name":"Sujan Nepal","email":"[email protected]","created_at":"2018-01-26 16:18:56","updated_at":"2018-01-26 16:18:56"}' for column 'user_id' at row 1 (SQL: insert into profiles (user_id, name, designation, profile_pic, updated_at, created_at) values ({"id":1,"name":"Sujan Nepal","email":"[email protected]","created_at":"2018-01-26 16:18:56","updated_at":"2018-01-26 16:18:56"}, Sujan Nepal, Developer, http://localhost/myblog/public/uploads/IMG_0251.JPG, 2018-01-29 16:53:31, 2018-01-29 16:53:31))

Actually I think it arise because of inserting image, but I could not solve it.

Please suggest me how to solve this.

Screenshot of error

2
Can you show as the code? As it seems like you're not building your query right - you're specifying the whole model serialized as JSON as the first argument in your SQL query (so you're trying to insert a record which has id of {"id":1,"Name":"..",etc.} and that messes up the whole query. - Giedrius
$profiles = new profile; $profiles->user_id = Auth::user(); $profiles->name = $request->input('name'); $profiles->designation = $request->input('designation'); if(Input::hasFile('profile_pic')){ $file = Input::file('profile_pic'); $file->move(public_path(). '/uploads', $file->getClientOriginalName()); $url = URL::to("/").'/uploads/'. $file->getClientOriginalName(); } $profiles->profile_pic = $url; $profiles->save(); - Everest
Schema: public function up() { Schema::create('profiles', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id'); $table->string('name'); $table->string('designation'); $table->string('profile_pic'); $table->timestamps(); }); } - Everest

2 Answers

1
votes

Based on the code in your comments, you have this line:

$profiles->user_id = Auth::user();

That should instead be:

$profiles->user_id = Auth::user()->id;

What's happening here is you're setting the user_id attribute to the entire User object returned from Auth::user(). The object probably uses toString() when it hits the database driver which looks like it serializes into a json string.

0
votes

For New Comer Like Me , You have to Check

{{ $party->id }}

Party variable from Party Model. You have to pass the

id

with this. CHeck sure in your blade. Just Pass The

id through variable.

Hope You! Got It.