Insert Query use in Laravel

Insert Query use in Laravel 5.8, Insert Query use in Laravel 5.7, Insert Query use in Laravel 5.6, Insert Query use in Laravel 5.5, Insert Query use in Laravel 5.4, Insert Query use in Laravel 5.3, Insert Query use in Laravel 5.2, Insert Query use in Laravel 5.1

 

How the value is inserted in laravel Framework.And you can read and read it easily.In laravel php is written in a slightly different way, but if you know the query of php, then you can easily understand it. The query of insert in laravel is written in this way.

DB::table('users')->insert([
'email' => '[email protected]',
'username' => 'rahul'
]);

Without creating a model, you can insert data from this query. But if you want to insert the data after you create the model then the query of the insert in the laravel is written in such a way that you have to write the model name.

Insert query syntex With using Modelname in Laravel

Modelname::insert([
'tablename_1' => 'value1',
'tablename_2' => 'value2'
]);
User::insert([
'email' => '[email protected]',
'username' => 'rahul'
]);