[英]How to display date selected from blade to blade?
I have a form in my blade with 2 dates for user to select like: 我的刀片中有一个带有2个日期的表单,供用户选择:
<form role="form" action="{{action('AltHr\Chatbot\PreBuiltController@viewgraphByDate', [$companyID])}}" autocomplete="off" method="POST">
{{csrf_field()}}
<div class="form-group-attached">
<div class="row">
<div class="col-lg-6">
<div class="form-group form-group-default required" >
<label>From</label>
<input type="date" class="form-control" name="from" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group form-group-default required" >
<label>To</label>
<input type="date" class="form-control" name="to" required>
</div>
</div>
</div>
</div>
<br/>
<button class="btn alt-btn-black btn-sm alt-btn pull-right" type="submit">Filter Date</button>
</form>
So in my controller function I have did this: 因此,在我的控制器功能中,我这样做:
$dateFrom = [$request->from];
$dateTo = [$request->to];
Then I tried to dd();
然后我尝试dd();
the value of datefrom
and dateto
and I am able to show it, but now I want to know how can I display this 2 values back in my blade file? 我可以显示datefrom
和dateto
的值,但是现在我想知道如何在刀片文件中显示这2个值?
In my return view I have compact()
the 2 values also. 在我的返回视图中,我也有compact()
两个值。
you can use laravel form model binding to show selected values in laravel blade. 您可以使用laravel表单模型绑定来显示laravel刀片中的选定值。
or 要么
<input type="date" class="form-control" name="to" value="{{$to}}" required>
here $to is your returning date from controller to view in compact 这里$ to是您从控制器返回以紧凑形式查看的日期
Try and update your output method from the comment from the post above to: 尝试将输出方法从以上文章的评论中更新为:
... ...
$dateFrom = $request->from;
$dateTo = $request->to;
$data = [
'companyID' => $companyID,
'match' => $match,
'noAnswer' => $noAnswer,
'missing' => $missing,
'email' => $email,
'pdf' => $pdf,
'image' => $image,
'video' => $video,
'text' => $text,
'totalMedia' => $totalMedia,
'dateFrom' => $dateFrom,
'dateTo' => $dateTo
];
return view('AltHr.Chatbot.viewgraph', $data);
... ...
Since you stated this is live loading the request to the page you may want to add $request->flash();
由于您已声明这是实时将请求加载到页面,因此您可能需要添加$request->flash();
to top beginning of the receiving method. 最先开始接收方法。
Firstly use Carbon in your Controller 首先在您的控制器中使用Carbon
use Carbon\Carbon;
then do this in your blade file 然后在刀片文件中执行此操作
<input type="date" class="form-control" name="to" value="{{\Carbon\Carbon::parse($dateFrom)}}" required>
you can also format the date if you like to 您还可以根据需要格式化日期
<input type="date" class="form-control" name="to" value="{{\Carbon\Carbon::parse($dateFrom)->format('Y-m-d))}}" required>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.