ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

How to use Insert Statement in Laravel?

user-image
تم إضافة السؤال من قبل Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited
تاريخ النشر: 2017/09/28
Murtaza Khokhawala
من قبل 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
من قبل 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
من قبل AHMAD ATHAMNEH , Senior Back-end Engineer & Angular developer & DBA , Edzance

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

'id'=>1,

'name'=>'Web technology',

'city_id'=>10

]);

Waleed Ikhlaq
من قبل 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
من قبل Arun Raj G S , CRM Administrator & PHP Developer , ME Group

Use Save() , If you want to update also

Julfkar  Moh Umar
من قبل Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited

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

المزيد من الأسئلة المماثلة