SleepWalker
SleepWalker

Reputation: 637

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

Upvotes: 1

Views: 249

Answers (1)

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

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);

Upvotes: 1

Related Questions