2017-05-02 71 views
1

後,我用的引導數據輸入選擇在我的表格的日期。我想在提交表格後保留日期。它已經幾天了,我開始研究,但至今還沒有找到一個解決方案。在我的項目,我使用Laravel 5.4和日期,我使用的是碳。 Laravel的顯示日期字段值表單提交

{{ old('input_date') }} 

只是不工作。如果有人能幫我找到解決辦法,那將非常感激。

這是我的控制器代碼:

public function showMisHistory() { 
    $mises = ''; 
    return view('uploads.mis_history', [ 
     'mises' => $mises, 
    ]); 
} 
public function showMisHistoryBetweenDates (Request $request) { 
    $this->validate($request, [ 
     'start_date' => 'required', 
     'end_date' => 'required', 
    ]); 
    $mises = Mis::where('uploader_pin', Auth::user()->pin)->whereBetween('date_of_data_type', array($request->start_date, $request->end_date))->get(); 
    // $mises = Mis::where('uploader_pin', Auth::user()->pin)->get(); 
    $totalLoanAmount = collect($mises)->sum('principal_loan_amount'); 
    $totalPremium = collect($mises)->sum('premium'); 
    $row_number = 1; 
    return view('uploads.mis_history', [ 
     'mises' => $mises, 
     'totalLoanAmount' => $totalLoanAmount, 
     'totalPremium' => $totalPremium, 
     'row_number' => $row_number, 
    ]); 
} 

這是我使用的形式。

<form action="{{ route('misHistoryBetweenDates') }}" method="POST" class="date-search-form"> 
       {{ csrf_field() }} 
       <div class="col-md-5"> 
        <div class="form-group"> 
         <label class="col-sm-2 control-label">From</label> 
         <div class="col-sm-10"> 
          <input type="date" name="start_date" class="form-control" value="{{ old('start_date') }}"> 
         </div> 
         @if (old('start_date')) 
         <label class="col-sm-2 control-label"></label> 
         <div class="col-sm-10"> 
          <span id="helpBlock" class="help-block">{{ old('start_date') }}</span> 
         </div> 
         @endif 
        </div> 
       </div> 
       <div class="col-md-5"> 
        <div class="form-group"> 
         <label class="col-sm-2 control-label">To</label> 
         <div class="col-sm-10"> 
          <input type="date" name="end_date" class="form-control" value="{{ old('end_date') }}"> 
         </div> 
         @if (old('end_date')) 
         <label class="col-sm-2 control-label"></label> 
         <div class="col-sm-10"> 
          <span id="helpBlock" class="help-block">{{ old('end_date') }}</span> 
         </div> 
         @endif 
        </div> 
       </div> 
       <div class="col-md-2"> 
        <div class="form-group"> 
         <input type="submit" name="submit" class="btn btn-primary"> 
        </div> 
       </div> 
      </form> 
+0

請出示您的控制器代碼 –

+1

可能是因爲日期的格式... –

回答

0

我已經通過發送start_dateend_date分別解決了這個問題。下面是我做的:

public function showMisHistoryBetweenDates (Request $request) { 
$this->validate($request, [ 
    'start_date' => 'required', 
    'end_date' => 'required', 
]); 
$start_date = $request->start_date; 
$end_date = $request->end_date; 
$mises = Mis::where('uploader_pin', Auth::user()->pin)->whereBetween('date_of_data_type', array($request->start_date, $request->end_date))->get(); 
$totalLoanAmount = collect($mises)->sum('principal_loan_amount'); 
$totalPremium = collect($mises)->sum('premium'); 
$row_number = 1; 
return view('uploads.mis_history', [ 
    'mises' => $mises, 
    'totalLoanAmount' => $totalLoanAmount, 
    'totalPremium' => $totalPremium, 
    'row_number' => $row_number, 
    'start_date' => $start_date, 
    'end_date' => $end_date, 
]); 

}

並在視圖:

<form action="{{ route('misHistoryBetweenDates') }}" method="POST" class="date-search-form"> 
       {{ csrf_field() }} 
       <div class="col-md-5"> 
        <div class="form-group"> 
         <label class="col-sm-2 control-label">From</label> 
         <div class="col-sm-10"> 
          <input type="date" name="start_date" class="form-control" value="{{ $start_date }}"> 
         </div> 
        </div> 
       </div> 
       <div class="col-md-5"> 
        <div class="form-group"> 
         <label class="col-sm-2 control-label">To</label> 
         <div class="col-sm-10"> 
          <input type="date" name="end_date" class="form-control" value="{{ $end_date }}"> 
         </div> 
        </div> 
       </div> 
       <div class="col-md-2"> 
        <div class="form-group"> 
         <input type="submit" name="submit" class="btn btn-primary"> 
        </div> 
       </div> 
      </form> 

這不是我一直在尋找,但沒有解決的問題現在。

1

您不返回舊的輸入。 Laravel需要使用withInput方法

public function showMisHistoryBetweenDates (Request $request) 
{ 
$this->validate($request, [ 
    'start_date' => 'required', 
    'end_date' => 'required', 
]); 
$mises = Mis::where('uploader_pin', Auth::user()->pin)->whereBetween('date_of_data_type', array($request->start_date, $request->end_date))->get(); 
// $mises = Mis::where('uploader_pin', Auth::user()->pin)->get(); 
$totalLoanAmount = collect($mises)->sum('principal_loan_amount'); 
$totalPremium = collect($mises)->sum('premium'); 
$row_number = 1; 
return view('uploads.mis_history', [ 
    'mises' => $mises, 
    'totalLoanAmount' => $totalLoanAmount, 
    'totalPremium' => $totalPremium, 
    'row_number' => $row_number, 
])->withInput($request->all()); 

}

返回輸入我希望這將是對你有用。

+0

還不行。我想展示的形式提交後,在引導日期字段選擇的日期。 –