Skip to content
Advertisement

Accessor for relation objects in Laravel

this is my Category model:

JavaScript

and when i call it in route for get all object like this:

JavaScript

it seems accessor not work and i can’t get ‘Foo’ in category’s media object

Advertisement

Answer

You can use withDefault():

JavaScript

When there is no result, it returns a Media instance with the given attributes.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement