jeudi 20 octobre 2016

Get the last inserted id using laravel

I am stuck with a problem . i need the last inserted id from the table which is to be added to same table, i.e in my table i 've two fields "id" and "translation-of" they both should save the same value. Id field is auto increment.How to implement this???? Am also uploading the categories using excel in that case also same problem... Please help me with this....

my controller function is

$insert[] = ['translation_lang'=>'en','parent_id' =>$a[0],'name' => $value->name,'slug' =>$value->name,'description' => $value->description,'picture'=>$pic,'active'=>1];

$last_id =    \DB::table('categories')->max('id');  

if(!empty($insert)){

                            \DB::table('categories')->insert($insert);
                                                            \DB::table('categories')->where('id2',$last_id)->update(['translation_of' => $last_id]);
                            return Redirect::to('admin/category');
                        }

Waiting for a response.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire