dongmu7335
dongmu7335
2017-04-11 05:13
浏览 67

当我尝试使用laravel中的datepicker更新日期字段时,在数据库中更新空白日期

When I try to update my form with date field having jquery datapicker it store empty value on my database so the date field not updated in my form ..I am using date datatype in database for date field..

I added this in html field

<input type="text" id="datepicker" value="{{ old('datetime', $site->datatime) }}" name="datatime">

This is inside my controller

$site->update([
            'name'=>$request['name'],
            'copyright'=> $request['copyright'],
            'is_active'=>$request['status'] == 'true' ? 1 : 0,
            'message'=>$request['message'],
            'datatime'=>$request['datetime'],
            'url'=>$request['url'],
            'metadata'=>$request['metadata']

        ]);
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dq05304
    dq05304 2017-04-11 05:21
    已采纳

    This is most probably due to the wrong date format. Mysql accept YYYY-MM-DD for the date format. you can work around with the date e.x

    $site->update([
            'name'=>$request['name'],
            'copyright'=> $request['copyright'],
            'is_active'=>$request['status'] == 'true' ? 1 : 0,
            'message'=>$request['message'],
            'datatime'=> date('Y-m-d', strtotime($request['datetime'])),
            'url'=>$request['url'],
            'metadata'=>$request['metadata']
    
        ]);
    
    点赞 评论
  • dongyinpan9284
    dongyinpan9284 2017-04-11 05:18
    <input type="text" id="datepicker" value="{{ old('datatime', $site->datatime) }}" name="datatime">
    

    Your form input name is "datatime" and you print date as datetime. try above code and one thing Database support YYYY-DD-MM HH:MM:SS format.

    点赞 评论

相关推荐