Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

How to use Insert Statement in Laravel?

user-image
Question ajoutée par Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited
Date de publication: 2017/09/28
Murtaza Khokhawala
par Murtaza Khokhawala , I.T. Head of Department , Royal Group of Companies

Create an Instance of Model Class then Assign the values to the respected fields and the save

                $data = new Staff();                 $data->sfullname = $request['fullname'];                 $data->susername = $request['username'];                 $data->spassword = openssl_encrypt($request['password'], $ciphering, $encryption_key, $options, $encryption_iv);                 $data->scontact = $request['phone'];                 $data->semail = $request['email'];                 $data->sdoj = $request['doj'];                 $data->sdob = $request['dob'];                 $data->sdesignation = $request['designation'];                 $data->scompany = $request['companyname'];                 $data->sreporting = $request['reporting'];                 $data->ssecurity = $request['security'] ? '7' : '2';                 $data->smultiple = $request['multiplesite'] ? '1' : '0';                 $data->active = "1";                 $data->sgrouplevel = "0";                 $data->sgroupowner = "Self";                 $data->save();

 

Lanka Senanayaka
par Lanka Senanayaka , Senior Software Engineer , Ensiz former Fullstack Labs

For laravel 5

First define fillables in model

 

App\\ModelName::create(["field1"=>"value1","field2"=>"value2"]);

AHMAD ATHAMNEH
par AHMAD ATHAMNEH , Senior Back-end Engineer & Angular developer & DBA , Edzance

\\DB::table('users')->insert([

'id'=>1,

'name'=>'Web technology',

'city_id'=>10

]);

Waleed Ikhlaq
par Waleed Ikhlaq , Full Stack Web Developer , iWebMonster

two ways to insert statement or data in laravel:

 

1- Use create method

2- Use save method

 

For more you can study on it in laravel docs.

Arun Raj G S
par Arun Raj G S , CRM Administrator & PHP Developer , ME Group

Use Save() , If you want to update also

Julfkar  Moh Umar
par Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited

DB::insert('insert into users (id, name, city_id) values (?, ?)', [1, 'Web technology',10]);

More Questions Like This