limeleaf's avatar

The best place for formating model outup

Where is the best place for formating model output? I have model called Event. Then I need to format results from the method all() of that model for using with fullCalendar js plugin.

There is an example of method for formating output:


foreach ($events as $key => $event) {
            $data[$key] = [
                'allDay'     => true,
                'color'      => $event->course->color,
                'end'        => Carbon::createFromFormat("Y-m-d", $event->end)->addDay()->toDateString(),
                'start'      => $event->start,
                'title'      => $event->course->name . ' – ' . $event->trainers->pluck('name')->implode(', '),
                'trainer_id' => $event->trainers()->pluck('trainers.id')->toJson(),
            ];
        }

Where should be this method placed? Model, Controller, Helper. Or how to do itl

I possible to do somethink like this:


Event::all()->toFullCalendar();

Thank you in advance for your suggestions

0 likes
2 replies

Please or to participate in this conversation.