Get the Last Inserted Id Using Laravel Eloquent

I’m currently using the below code to insert data in a table: <?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); … Read more

How to Create Multiple Where Clause Query Using Laravel Eloquent?

I’m using the Laravel Eloquent query builder and I have a query where I want a WHERE clause on multiple conditions. It works, but it’s not elegant. Example: $results = User::where(‘this’, ‘=’, 1) ->where(‘that’, ‘=’, 1) ->where(‘this_too’, ‘=’, 1) ->where(‘that_too’, ‘=’, 1) ->where(‘this_as_well’, ‘=’, 1) ->where(‘that_as_well’, ‘=’, 1) ->where(‘this_one_too’, ‘=’, 1) ->where(‘that_one_too’, ‘=’, 1) ->where(‘this_one_as_well’, … Read more