mercredi 21 septembre 2016

$fillable and create() not working

I've just installed new laravel project. After that, I created new Model but when I use create() function, it just show me that my new rows has been duplicated.

This is my code:

protected $fillable = ['id', 'setting_name', 'expected_type', 'default_val', 'modified_val', 'updated_at', 'created_at', 'is_deleted'];
    // protected $guarded = ['created_at', 'updated_at'];
function test() {
    $input = ['setting_name' => 'Test',
                    'expected_type' => '123',
                    'default_val'=>'123',
                    'modified_val'=>'123'];
                    // dd($input);
//both next two lines do not working
//Setting::create($input);
    Setting::firstOrNew($input)->save();
    return Setting::firstOrNew($input);
}

I checked the error :

"Integrity constraint violation: 1062 Duplicate entry '' for key 'setting_name' (SQL: insert into settings (updated_at, created_at) values (1474452834, 1474452834))"

What i did wrong ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire