Home » Php » Laravel database insert query

Laravel database insert query

Posted by: admin November 30, 2017 Leave a comment

Questions:

I’m trying to do simple insertion in database and im getting the following error

call_user_func_array() expects parameter 1 to be a valid callback, no
array or string given

The insertion code look like this

DB::insert('insert into users (id, name) values (?, ?)', array(1, 'Dayle'));

It’s a basic query for laravel, but it won’t work why?


Answers:
DB::table('users')->insert(
     array(
            'id'     =>   '1', 
            'name'   =>   'Dayle'
     )
);

or

$values = array('id' => 1,'name' => 'Dayle');
DB::table('users')->insert($values);

But why are you inserting an ID? Should this not be an auto incremented value?