laravel 5 How do I download the latest id added to the model? It's simple, I have a form that sends data via post to:
route:
Route::get('/insert/{data}', 'IdataController@ins');
Route::post('/insert/{data}', 'IdataController@add_data');
controller:
public function ins($data = 1){
if($data == 1){
//display data
}elseif($data == 2){
// this place I need last insert id
}
}
public function add_data(Request $request, $data){
if($data == 1){
$r = $this->insert_my([
'name'=>$request->name,
'relationid'=>$request->relationid
]);
return $r;
}else($data ==2){
//next operations
}
}
private function insert_my($data){
$r= Insertmodel::create([
'name'=>$data['name'],
'relationid'=>$data['relationid']
]);
return Redirect::to('insert/2');
}
The best solution for me is to download last id from Model. But how to do it ?
id needs to get in this place:
elseif($data == 2){
// this place I need last insert id
}