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?
In Laravel the database query builder provides an easy interface to create and run database queries. It can be used to perform all the database operations in your application, from basic DB Connection, CRUD, Aggregates, etc. and it works on all supported database systems like a champ.
Code: $user = new User; $inputArry = array('data1' => $request['field1'], 'data2' => $request['field2'], 'data3' => $request['field3'], ); $user->create($inputArry); $user->xyz()->create([ 'user_id' => $user->id, 'name' => $request['name'], 'about' => $request['desc'], 'tag' => $request['tag'], ]);
After configuring the database, we can retrieve the records using the DB facade with select method. The syntax of select method is as shown in the following table. Run a select statement against the database.
$user['id'] = 1;
$user['name'] = 'dale';
DB::table('users')->insert($user);
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With