如何使用 laravelcollective 在 Laravel 中使用 datetimepicker

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51968355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:59:46  来源:igfitidea点击:

How to use datetimepicker in Laravel using laravelcollective

phplaravel

提问by Mirich

Good day to all I was creating a Laravel project and I was wondering how to put and use datetimepicker in the view if possible with laravelcollective if not please suggest something. I have used form::date but creates a simple textbox which is inappropriate. The code I ams using now:

大家好,我正在创建一个 Laravel 项目,我想知道如何在视图中放置和使用 datetimepicker,如果可能的话,laravelcollective 如果没有,请提出一些建议。我使用了 form::date 但创建了一个不合适的简单文本框。我现在使用的代码:

{{Form::date('DateOfProduction', \Carbon\Carbon::now(), ['class'=>'form-control','style' => 'max-width: 200px'])}}

采纳答案by afikri

In your app blade template, you need to do is to include jquery and bootstrap datetimepicker before your javascript like

在您的应用程序刀片模板中,您需要做的是在您的 javascript 之前包含 jquery 和 bootstrap datetimepicker

<script>
  $(function() {
    $( "#your_datepicker_id" ).datepicker({
    // dateFormat: 'dd/mm/yyyy',
    dateFormat: 'd/m/Y',
    changeMonth: true,
    changeYear: true});
    });
  </script>

then in your blade template that extending app, inside the form do as below

然后在扩展应用程序的刀片模板中,在表单中执行如下操作

{!! Form::open(['route'=>'some-of-your-post-function', 'method'=>'POST', 'files'=>'true','class'=>'form']) !!}       

    <div class="form-group">
          {!! Form::label('Uploading Date') !!}
          {!! Form::text('date_of_upload',null, [
            'class' => 'form-control',
            'id' => 'your_datepicker_id',
          ]) !!}

      </div>
{!! Form::close() !!}

That's simple as that, hope that helps

就这么简单,希望能帮到你

回答by Shalto

Include this in your head

把这个记在你的脑海里

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
in your footer



<script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

and your input

和你的输入

{{ Form::text('date', '', array('id' => 'datepicker')) }}