Return model with laravel when it was created
Since you've created a new object, and not retrieved one from the database, the only attributes it will know about are the ones that you set.
If you'd like to get the rest of the fields on the table, you will need to re-retrieve the object after you save it.
// create the new record.
// this instance will only know about the fields you set.
$organization = Organization::create([
'description' => $description,
]);
// re-retrieve the instance to get all of the fields in the table.
$organization = $organization->fresh();
$savedOrganization = Organization::create(
[
'description' => $description
]
);
return response()->json([
'organization' => $savedOrganization,
], 200)
And this code is useless
if (!$organization) {
throw new \Exception("No se guardo la organizacion");
}