Toni Toni - 6 months ago 35
PHP Question

laravel eloquent inserts empty record to database

Am using Laravel Eloquent

create::
to insert record, but it inserts and empty record having values in only the id and timestamps.

$data['fname'] = $request->input('fname');
$data['lname'] = $request->input('lname');
$data['email'] = $request->input('email');
$data['phone'] = $request->input('phone');
RefUsers::create($data);


Then in my
RefUsers
models I have

protected $fillable = array('fname, lname, email,phone');
public $timestamps = false;


It runs without error, but it inserts empty record to db. Can anybody help?

jah jah
Answer

Fillable is an array of strings, so each field, should be on its own index like:

protected $fillable = array('first_name', 'last_name', 'email');
Comments