Mic*_*ata 3 php json laravel postgresql-9.4
我需要将保存为json的新模型发送到前面,但我无法看到列组织响应
这是我的模特
class Organization extends Model
{
protected $table = "core.organizations";
protected $fillable = ['description'];
public $primaryKey = "organizationid";
public $incrementing = false;
public $timestamps = false;
}
Run Code Online (Sandbox Code Playgroud)
这是我的功能
public function saveOrganization(Request $request)
{
try {
$description = $request->input('description');
$organization = new Organization();
$organization->description = $description;
$organization->save();
if (!$organization) {
throw new \Exception("No se guardo la organizacion");
}
return response()->json([
'organization' => $organization,
], 200);
} catch (\Exception $ex) {
return response()->json([
'error' => 'Ha ocurrido un error al intentar guardar la organización',
], 200);
}
}
Run Code Online (Sandbox Code Playgroud)
这是回应
{"organization":{"description":"Restobar"}}
Run Code Online (Sandbox Code Playgroud)
我能怎么做?
谢谢!!
pat*_*cus 11
由于您已创建了一个新对象,而未从数据库中检索到该对象,因此它将了解的唯一属性是您设置的属性.
如果您想要获取表中的其余字段,则需要在保存后重新检索该对象.
// 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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4053 次 |
| 最近记录: |