Boris Pavlovski
Boris Pavlovski

Reputation: 725

Save inserts empty row Laravel 5.3

I'm trying to make Laravel ORM working and it keeps inserting empty records in database. The ID created_at and updated_at are correctly inserted but the values are not. Here are the files:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class TesterTest extends Model
{    
    protected $fillable = ['name','value'];
    public $name;
    public $value;
}

The migration file:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTestTable extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
     public function up()
    {
        Schema::create('my_tests', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->integer('value');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('my_tests');
    } }

And this is how Im calling it:

$flight = new TesterTest;

$flight->name = "Tester1";

$flight->save();

There is a something Im missing but can't figure it out.

Upvotes: 0

Views: 309

Answers (1)

CUGreen
CUGreen

Reputation: 3186

I would say that adding in public $name; and public $value; in your model is causing problems. Try removing those two lines.

Upvotes: 2

Related Questions