亲爱的,
我正在尝试创建一个基于laravel的项目,因为我有一个部分来显示剩余的日子...我的数据库中有3个问题,它们是
因为sub_end_date是在jQuery的帮助下自动计算的。因此它将存储在数据库中1-9-2020 (M-D-Y)。所以我的问题是我无法计算剩余的天数。.我用谷歌搜索并得到了一些类似的解决方案,我将在下面添加,但仅适用于一行(或最后添加的行),并在我的blade.php中页面,它在循环中显示相同的结果。]
//subscription_details.blade.php
@extends('layouts.app')
@section('body')
<center>
</br>
<div class="col-lg-5">
<h4>subscribtion details</h4></br>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Phone Number</th>
<th scope="col">Type Of Subscription</th>
<th scope="col">Start Date</th>
<th scope="col">End Date</th>
<th scope="col">Days Remaining</th>
</tr>
</thead>
<tbody>
<tr>
@foreach($customer as $row)
<th scope="row">{{$row->name}}</th>
<td>{{$row->phone}}</td>
<td>{{$row->subscription}}Month</td>
<td>{{$row->sub_start_date}}</td>
<td>{{$row->sub_end_date}}</td>
<td>{{$count}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</center>
@endsection
我的控制器代码是
//SubscriptionController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\customer;
use Carbon\Carbon ;
class SubscriptionController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$now = Carbon::now();
$customer =customer::all();
foreach($customer as $row)
{
$end_date = $row->sub_end_date;
$cDate = Carbon::parse($end_date);
$count = $now->diffInDays($cDate );
}
return view('subscription_details',compact('customer','count'));
}
截至目前,我正在得到这个
订阅详细信息
结果就像提交开始日期= 2019-12-01,提交结束日期= 2019-12-01 剩余天数为每个大棚260天请帮助我找到解决方法
在客户模型中定义了mutator属性: