[英]laravel mass assignment setting not working
When I insert user information into my app I use the following code: 当我将用户信息插入我的应用程序时,我使用以下代码:
$userId = Auth::user()->user_id;
$newUserInfo = UserInfo::create([
'u_info_id' => $userId,
'u_first_name' => Input::get('u_first_name'),
'u_last_name' => Input::get('u_last_name'),
'u_phone_number' => Input::get('u_phone_number'),
'u_address' => Input::get('u_address'),
'u_state_id' => Input::get('u_state_id'),
'u_city_id' => Input::get('u_city_id'),
'u_zip' => Input::get('u_zip')
]);
But I cant do this 'u_info_id' => $userId
since that will force me to make u_info_id fillable for the mass assignment. 但是我无法执行此'u_info_id' => $userId
因为这将迫使我使u_info_id可用于批量分配。
So my problem is, how can I use 'u_info_id' => $userId
without making u_info_id fillable for mass assignment. 所以我的问题是,如何在不使u_info_id可填充进行批量分配的情况下使用'u_info_id' => $userId
。 I dont want users to be able to edit u_info_id . 我不希望用户能够编辑u_info_id 。 That field should be inserted backend. 该字段应插入后端。
OR, do I only need to set fillable mass assignment when using laravel ->fill() ? 或者,仅在使用laravel- > fill()时才需要设置可填充质量分配吗?
I solved it like this: 我这样解决了:
//Validation of inputs //验证输入
$newUserInfo = new UserInfo();
$newUserInfo->u_info_id = $userId;
$newUserInfo->u_first_name = Input::get('u_first_name');
$newUserInfo->u_last_name = Input::get('u_last_name');
$newUserInfo->u_phone_number = Input::get('u_phone_number');
$newUserInfo->u_address = Input::get('u_address');
$newUserInfo->u_state_id = Input::get('u_state_id');
$newUserInfo->u_city_id = Input::get('u_city_id');
$newUserInfo->u_zip = Input::get('u_zip');
$newUserInfo->save();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.