I have this code
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);
}
}
When I tried return $request->all()
to see whether the value of DonorPrefix
, UserID
, and DonorPhotoURL
has been stored in the array of requests or not, the returned JSON seems to have all of these three variables.
{
"DonorCitizenID": "1000000000000",
"DonorPrefix": "คุณ",
...
"UserID": 1,
"DonorPhotoURL": "/uploads/1465963777.png",
"DonorPhoto": {}
}
But when I tried return $donor
, which is the object of the Donor, defined its value by the $donor = \App\Donor::create($requests->all());
, the value of UserID
and DonorPhotoURL
is NOT stored, but the DonorPrefix
does have the value of Mx
. Here are the JSON for $donor
:
{
"DonorCitizenID": "1000000000000",
"DonorPrefix": "คุณ",
...
"updated_at": "2016-06-15 04:16:47.000",
"created_at": "2016-06-15 04:16:47.000",
"DonorID": 39
}
(The ...
represents some data omnitted for cleaner snippet)
I am sure the database itself has the column name of DonorPhotoURL
and UserID
, but it doesn't still store the values.