4 months ago

A small refactoring

Posted 4 months ago by Stillfinder

Hi, I have a similar piece of code in the static method of my Model and inside my Controller. I am trying to find a better way to refactor this, but am not sure about a better solution.

Code from my Controller:

$jsTags =  $post->tags->pluck('name', 'slug')->map(function ($value, $key) {
            return ['key' => $key, 'value' => $value];

Code from my Model:

public static function allJson()
        return Tag::all()->pluck('name', 'slug')->map(function ($value, $key) {
            return ['key' => $key, 'value' => $value];

Thanks for any help.

Please sign in or create an account to participate in this conversation.