1
votes

I have a Migration like this:

public function up()
    {
        Schema::create('movies', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('link');
            $table->integer('year');
            $table->string('actor');
            $table->string('director');
            $table->integer('imdb');
            $table->boolean('watched')->default(0);
            $table->integer('starred');
            $table->timestamps();
        });
    }

But when I want to store some data into this table, I get this error:

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

Here is my store method:

public function store(Request $request)
    {
        $new = new Movie();
        $new->name = $request->name;
        $new->link = $request->link;
        $new->year = $request->year;
        $new->actor = $request->actor;
        $new->director = $request->director;
        $new->imdb = $request->imdb;
        $new->starred = $request->starred;
        $new->watched = $request->watched;
        $new->save();
    }

I don't know what is going wrong here, that shows me this error... If you know, plz let me know.

Thanks in advance.

UPDATE #1: Result of dd($request):

enter image description here

UPDATE #2: Full error:

Illuminate\Database\QueryException SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'on' for column bia2film.movies.watched at row 1 (SQL: insert into movies (name, link, year, actor, director, imdb, starred, watched, updated_at, created_at) values (Godfather, asdsadsa, 1232, Brando, Copola, 9, 5, on, 2021-04-30 13:41:20, 2021-04-30 13:41:20))

1
can you dd your request? dd($request); and show us the result - Jack
Which value triggers this error? Please, post full error messages in questions, don't cut them off. There are two integer fields and we don't know what's in your request. - El_Vanja
@Jack I just added it... - user7424490
@El_Vanja Illuminate\Database\QueryException SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'on' for column bia2film.movies.watched` at row 1 (SQL: insert into movies (name, link, year, actor, director, imdb, starred, watched, updated_at, created_at) values (Godfather, asdsadsa, 1232, Brando, Copola, 9, 5, on, 2021-04-30 13:41:20, 2021-04-30 13:41:20))` - user7424490
$table->boolean('watched')->default(0); but you try to store a string 'on'. - El_Vanja

1 Answers

1
votes

from Your Screenshot You are trying to store a string value to the boolean column

$table->boolean('watched')->default(0);

Try To change Your Schema from

        $table->boolean('watched')->default(0);
    to
    
         $table->enum('watched',['on','off'])->default('off');

or Change the value of request to True or false.

I prefer Sencond method