phplaraveleloquentsql-insert

Call Laravel's create() method with only() and include a generated value to the payload


I am adding this (float) str_replace(',', '', $orders['grandtotal']) to my store function but I am having issue:

Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')'

Here's my store function look like

 $orders = Orders::create($request->only(
        'user_id',
        'status_id',
        'currency_id',
        'company_id',
        'purchase_no',
        'notes',
        'delivery_date',
        'grandtotal' =>(float) str_replace(',', '', $orders['grandtotal']),
        'publish'
    ));

issues


Solution

  • Try this code

     $data = $request->only(
        'user_id',
        'status_id',
        'currency_id',
        'company_id',
        'purchase_no',
        'notes',
        'delivery_date',
        'publish'
    );
    $data['grandtotal'] = (float) str_replace(',', '', $request->grandtotal);
    $orders = Orders::create($data);