2016-07-07 8 views
0

私のリスティングには旅行代金を差し引いています。私のフォームでは、そのリスティングのすべての旅行を表示します。私はどのように既存の旅行名をデータベースに挿入するかわかりません。私はあなたが何を意味するかを見せます。 フォームからテキストを取得してデータベースに挿入する方法 - Laravel 5.2

を(トリップ名と減少し価格が切り抜いた表になりますので、私は、I'amはプロモーションのリストを作成し、旅行を編集していないよ)私は左

の「旅」の名前を挿入する必要があります

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

はい、完璧なthatsの! – David

関連する問題