4external's avatar

Output model JSON Id for string

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" } }

0 likes
2 replies
morteza's avatar
morteza
Best Answer
Level 12

add this line to your model:

protected $incrementing = false;
1 like
4external's avatar

morteza, thank you!

correct version is

    public $incrementing = false;

Please or to participate in this conversation.