如何使用Laravel在db中发送二维数组数据

时间:2019-11-30 08:31:52

标签: laravel

<form method="post" id="payment-form" action="{{url('/charge-payment')}}">
    @csrf
    @foreach($bidder as $key=> $detail)
    {{--<input type="hidden" name="post_price" id="post_price">--}}

        <input type="hidden" name="bid_price[]"  class="removeLater" value="{{$detail->bid_price}}">
        <input type="hidden" name="post_id[]" class="removeLater" value="{{$detail->post_id}}">
        <input type="hidden" name="tutor_id[]" class="removeLater" value="{{$detail->tutor_id}}">
     @endforeach

    <div class="form-row">
        <label for="card-element">
           Credit or debit card
        </label>
        <div id="card-element">
        <!-- A Stripe Element will be inserted here. -->
        </div>
        <!-- Used to display form errors. -->
        <div id="card-errors" role="alert"></div>
    </div> {{-- @dd($bid->bid_price)--}}

     <button  class="margin-top-15 button full-width button-sliding-icon ripple-effect" >Submit Payment<i class="icon-material-outline-arrow-right-alt"></i></button>  
</form>
public function charge(Request $request)
{
    dd($request);
    foreach ($request->bid_price as $approver) {

        // Set your secret key: remember to change this to your live secret key in production // 
        // See your keys here:
        // https://dashboard.stripe.com/account/apikeys
        // \Stripe\Stripe::setApiKey('sk_test_dd1nMs2PEqbGLOF6SpsDIl0c00QPcwncXY');
        // Token is created using Checkout or Elements! // Get the payment
        // token ID submitted by the form:

        $token = $_POST['stripeToken'];
        $charge = \Stripe\Charge::create([
            'amount'      => $request->post_price * 100,
            'currency'    => 'usd',
            'description' => 'Example charge',
            'source'      => $token,
        ]);
        $id = Auth::user()->id;
        $payment = new Payment();
        $payment->tutor_id = $request->tutor_id;
        $payment->user_id = $id;
        $payment->post_id = $request->post_id;
        $payment->amount = $charge->amount;
        $payment->save();

        return redirect()->back();
    }
}

0 个答案:

没有答案