mardi 26 septembre 2017

Trying to get property of non-object Laravel API

The problem i ve got is when i am formating the API structure. Laravel returning an error trying to get property of non-object.

Function below:

  protected function format(Model $model)
{

    return [
        'id' => $model->id,
        'option' => $model->option->id,
        'value' => $model->value,
        'active' => $model->active,
    ];
}

If Option property is removed everything is working. Option is a FK to the current table.

Any advise how can i get the option ID from the parent table, or where to create the relationship. Many thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2yEkGnK
via IFTTT

Aucun commentaire:

Enregistrer un commentaire