Laravel Classroom image

Prashant  Nigam / Student / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14|Last
Lessons:-Fluent Query Builder

10.10 Insert
Finally, let’s store some data. All this time we have been looking at reading data but this will
be more fun! Well it’s quite simple really. To insert a new row all we have to do is provide a
key-value array to the insert() method, which is a trigger method by the way!
1 <?php
2
3 DB::table('shoes')->insert(array(
4 'color' => 'hot pink',
5 'type' => 'heels',
6 'size' => '12'
7 ));
Wait, lets grab the id thats created with this new row, it might be handy later? We can use
insert_get_id() with the same parameters for this.
1 <?php
2
3 $id = DB::table('shoes')->insert_get_id(array(
4 'color' => 'hot pink',
5 'type' => 'heels',
6 'size' => '12'
7 ));
That’s my weekend pair, let’s keep this between us. We now have a nice hot pink pair of heels
in size 12, stored in the shoes table of our database.

 

 
 
 

Prashant  Nigam

Skills    Laravel

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)