R
R
RMate2019-04-10 20:41:18
Laravel
RMate, 2019-04-10 20:41:18

How to use mutators in hasMany laravel?

Hello!
Got a question. There are 2 models, A and B . Model A is related to model B via hasMany .
Model B contains a date format field, as well as a mutator

protected $dates = [
      'time'
    ];

However, when fetching through a relation, the mutator is not applied to the given attribute and I get a bare string.
I also tried to make a crutch by writing a getTimeAttribute getter to model B , which would explicitly create a Carbon date from a string, which also did not work, because the attribute is not called) Surely there is a way to cope with this task simply and elegantly. Can you advise?)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question