/* Place uploaded images into appropriate columns. */
for($i = 1; $i <= 5; $i++)
{
if(Input::file('image' . $i . '.size') >= 1)
{
$randomName = substr(md5(rand(1,9999999)), 1, 15);
Input::upload('image' . $i, path('public') . 'uploads/backgrounds/', Auth::user()->username . $randomName . '.jpg');
$wedding= Wedding::where('wedding_owner', '=', Auth::user()->username)->first();
$wedding->image1 = $randomName;
$wedding->save();
}
}
用戶可以上傳5張照片。上傳的圖片應放置在image1, image2, image3, image4 and image5 columns
中wedding table
。如何爲名爲數組的數據庫列添加變量值?
基本上,
$wedding->image1 = $randomName;
應該是這樣的:
$wedding->image{$i} = $randomName;
我該如何解決這個問題?
已經列舉的字段名總是一個不好的設計 – 2013-05-12 14:02:56
的氣味爲什麼不把所有的值在環路比保存一次? – Rikesh 2013-05-12 14:03:21
@Rikesh謹慎地闡述一下? – Aristona 2013-05-12 14:04:48