LMSouq
php-dev Open

Get the Last Inserted Id Using Laravel Eloquent

SO
SoldierCorp
1 month ago
3 views
Problem Description
I'm currently using the below code to insert data in a table: <!-- language: php --> <?php public function saveDetailsCompany() { $post = Input::All(); $data = new Company; $data->nombre = $post['name']; $data->direccion = $post['address']; $data->telefono = $post['phone']; $data->email = $post['email']; $data->giro = $post['type']; $data->fecha_registro = date("Y-m-d H:i:s"); $data->fecha_modificacion = date("Y-m-d H:i:s"); if ($data->save()) { return Response::json(array('success' => true), 200); } } I want to return the last ID inserted but I don't know how to get it. Kind regards!

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base