Laravel不会存储offsetSet()定义的值

时间:2016-06-15 04:40:57

标签: php laravel

我有这段代码

0 observations created

当我尝试class DonorsController extends Controller { //Some code public function donorAddSave(Request $request){ if ($request->file('DonorPhoto')->isValid()) { $destinationPath = 'uploads'; // upload path $DonorPhotoURL = date_timestamp_get(date_create()).'.'.$request->file('DonorPhoto')->guessExtension(); $request->file('DonorPhoto')->move($destinationPath,$DonorPhotoURL); } $request->offsetSet('UserID',1); $request->offsetSet('DonorPhotoURL','/'.$destinationPath.'/'.$DonorPhotoURL); if(!$request->has('DonorPrefix')){ $request->offsetSet('DonorPrefix', 'Mx.'); } $donor = \App\Donor::create($request->all()); return redirect('/donor/'.$donor->DonorID); } } 查看return $request->all()DonorPrefixUserID的值是否已存储在请求数组中时,返回的JSON似乎拥有所有这三个变量。

DonorPhotoURL

但是,当我尝试返回{ "DonorCitizenID": "1000000000000", "DonorPrefix": "คุณ", ... "UserID": 1, "DonorPhotoURL": "/uploads/1465963777.png", "DonorPhoto": {} } (捐赠者的对象)时,$donor定义了其值,$donor = \App\Donor::create($requests->all());UserID的值未存储,但DonorPhotoURL确实具有DonorPrefix的值。以下是Mx的JSON:

$donor

{ "DonorCitizenID": "1000000000000", "DonorPrefix": "คุณ", ... "updated_at": "2016-06-15 04:16:47.000", "created_at": "2016-06-15 04:16:47.000", "DonorID": 39 } 表示为清洁代码段设置的一些数据

我确信数据库本身的列名为...DonorPhotoURL,但它仍然不存储值。

1 个答案:

答案 0 :(得分:0)

确保您的App\Donor模型在$fillable中包含该字段,以便mass assignment能够正常工作。