Laravel error when with method type when storing in database

  laravel

I am trying to pass a $request to Laravel function and store the data in a table and i get error

The API route

Route::post('/orderdetails/store/', '[email protected]');

The Laravel function

public function store(Request $request)
{
    $validator = Validator::make($request->all(), [
        'order_id' => 'required',
        'product_id' => 'required'
    ]);

    if ($validator->fails()) {
        $errors = $validator->errors();
        return response()->json($errors);
    }

    $order_id = $request->order_id;
    $product_id = $request->product_id;
    $order_details = OrderDetail::create(['order_id' => $order_id, 'product_id' => $product_id]);

    $success = 'Order Details Confirmed Successfully';

    return response()->json($success);
}

what I send to Postman and the error I get

The Error

Source: Laravel

Leave a Reply