4external
1 year ago

Output model JSON Id for string

Posted 1 year ago by 4external

Hi!

I have model with PK as string:

    protected $primaryKey = "receipt";
    protected $keyType = 'string';

in controller it's correctly saves to DB, but outputs JSON have "0" instead correct string:

        $order = new Order;

        $order->internal = $internal;
        $order->receipt = $receiptString;

        $order->save();

        $output = array(
                "data" =>$order,
        );

        return $this->asJson($output);

output is

{ "data": { "internal": "5e4408", "receipt": "0" } }

Please sign in or create an account to participate in this conversation.