2016-07-07 50 views
0

我爲我的列表插入降低的出行價格。在我的表單中,我顯示了該列表的所有行程。我不知道如何將已經存在的旅行名稱插入到數據庫中。我會告訴你我的意思。 (我不是編輯之旅,我'創造一個促銷上市,所以行程名稱和更低的價格將進入一個不同勢表)我需要插入左側如何從表單中獲取文本並將其插入數據庫 - Laravel 5.2

的「旅行」的名字

Muy Trips

我這是怎麼了表格佈局:

<form class="form" method="post" action="{{ route('user.promotion-store') }}"> 
 
        {{ csrf_field() }} 
 

 
<table class="table table-hover table-striped"> 
 
         <thead> 
 
         <tr> 
 
          <th>Trip</th> 
 
          <th>Price</th> 
 
          <th>Reduced Price</th> 
 
         </tr> 
 
         </thead> 
 
         <tbody> 
 
         @foreach($listings->trips as $trip) 
 
         <tr> 
 
          <td> 
 
           {{ $trip->name }} 
 
          </td> 
 
          <td> 
 
           ${{ $trip->cost }} 
 
          </td> 
 
          <td> 
 
           <div class="col-md-12"> 
 
            <div class="form-group{{ $errors->has('reduced_trip_price') ? ' has-error' : '' }}"> 
 
             <label>Your Reduced Price</label> 
 
             <input type="text" class="form-control" name="reduced_trip_price" id="reduced_trip_price" placeholder="Optional..."> 
 
             @if($errors->has('reduced_trip_price')) 
 
              <span class="help-block">{{ $errors->first('reduced_trip_price') }}</span> 
 
             @endif 
 
            </div> 
 
           </div> 
 
          </td> 
 
         </tr> 
 
         @endforeach 
 
         </tbody> 
 
        </table> 
 
    
 
    </form>

這是我怎麼插入:

public function store(ReducedTripRequest $request) { 

     $reducedTrips = ReducedTrips($request->all()); 
     $reducedTrips->save(); 

     return redirect()->back(); 
} 

回答

1

這種方式傳遞Trip name形式中的一個隱藏的輸入字段:

<input type="hidden" name="trip_name" value="{{ $trip->name }}"> 

然後在服務器端,您可以得到trip_namereduced_trip_price隨心所欲地做任何事情。

要在表格中插入例如:

<?php 
NewTable::create([ 
    'trip_name' => $request->input('trip_name'), 
    'reduced_trip_price' => $request->input('reduced_trip_price'), 
]); 
+1

是那完美! – David

相關問題