skip to Main Content

Please help me! I don’t know where am I wrong?

web.php:

Route::post('new-order-form', [OrderController::class, 'showNewOrderForm'])->name('new.order.form');

OrderController.php:

public function showNewOrderForm()
    {
        $products = SanPham::all();
        $employees = Employee::all();
        return view('order.new_order_form', compact('products', 'employees'));
    }

/order/new_order_form.blade.php

/order/order.blade.php:

$(document).ready(function(){
            // Hiển thị form tạo đơn hàng mới khi click
            $("#newOrderBox").click(function(){
                window.location.href = "{{ route('new.order.form') }}";
            });
});

I tried replacing GET, POST, PUT but it didn’t work.

2

Answers


  1. Route::get('new-order-form', [OrderController::class, 'showNewOrderForm'])->name('new-order-form');
    
    
    window.location.href = "/new-order-form";
    
    Login or Signup to reply.
  2. should have try any

    Route::any('new-order-form', [OrderController::class, 'showNewOrderForm'])->name('new.order.form');
    
    $(document).ready(function(){
                // Hiển thị form tạo đơn hàng mới khi click
                $("#newOrderBox").click(function(){
                    window.location.href = "{{ route('new.order.form') }}";
                });
    });
    

    if you have same function for view get and post you should try any method to achieved it

    Route::any('new-order-form', [OrderController::class, 'showNewOrderForm'])->name('new.order.form');
    
    $(document).ready(function(){
                // Hiển thị form tạo đơn hàng mới khi click
                $("#newOrderBox").click(function(){
                    window.location.href = "{{ route('new.order.form') }}";
                });
    });
    
    
    Route::get('new-order-form', [OrderController::class, 'showNewOrderForm'])->name('new.order.form');
    

    or use get if want to get only

    Route::get('new-order-form', [OrderController::class, 'showNewOrderForm'])->name('new.order.form');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search