vendredi 21 juin 2019

Form submission returns inputs Laravel

I'm trying to create a submission form, if a user submit the form it should redirect him to the next page which is in confirmation controller. So far it redirects back with the inputs like this {"shipping_city":"gfg","shipping_phone":"087484","shipping_name":"Hellle",}

Here is my code

CheckoutController

 public function store(Request $request)
 {
    foreach(session('cart')  as $productId =>$item);
    $product = product::find($productId);
    //Insert into orders table
    $order = Order::create([
        'shipping_city' => $request->city,
        'shipping_phone' => $request->phone,
         'shipping_name' => $request->name,
    ]);


    if ($order) {
        foreach(session('cart')  as $productId =>$item) {
           if (empty($item)) {
               continue;
           }
           $product = product::find($productId);
           OrderProduct::create([
            'order_id' => $order->id ?? null,
            'product_id' => $productId,
            'quantity' => $item['quantity'],
        ]);
       }
       return $order;
    }
    $cart = session()->remove('cart');
     return redirect()->route('confirmation.index');
   }

Checkout.blade

    <form action="" method="POST" id="payment-form">
        
         <div class=shippingform>
        <div class="form-group">
        </div>
        <div class="form-group">
            <label for="name">Name</label>
            <input type="text" class="form-control" id="name" name="name" value="" required>
        </div>

        <div class="half-form">
            <div class="form-group">
                <label for="city">City</label>
                <input type="text" class="form-control" id="city" name="city" value="" required>
            </div>

        </div> <!-- end half-form -->
            <div class="form-group">
                <label for="phone">Phone</label>
                <input type="text" class="form-control" id="phone" name="phone" value="" required>
            </div>
        <div class="spacer"></div>
        <div class="spacer"></div>
        <button type="submit" id="complete-order" class="buttons-primary full-width">Complete Order</button>
    </form>

ConfirmationController

  public function index()
 {
    {
        if (! session()->has('success_message')) {
            return redirect('/');
        }

        return view('thankyou');
    }
 }

Routes

 Route::post('/checkout', 'CheckoutController@store')->name('checkout.store');

Any help will be appreciated.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2FkV3NK
via IFTTT

Aucun commentaire:

Enregistrer un commentaire