I want to have a clean code.

Posted 4 months ago by joseluisac

Hi.

I'm developed a rest api with Laravel.

I have a doubt, i want to develop a foreach for this code, i think that is repeated code, i'll like to have my optimized code.

$estado = $query->pluck('estado')->unique()->values()->all();
$ciudad = $query->pluck('ciudad')->unique()->values()->all();
$municipio = $query->pluck('municipio')->unique()->values()->all();
$colonia = $query->pluck('colonia')->unique()->values()->all();
$cp = $query->pluck('cp')->unique()->values()->all();

$data = [
    'estado' => $estado,
    'ciudad' => $ciudad,
    'municipio' => $municipio,
    'colonia' => $colonia,
        'cp' => $cp,
];

Can you help me?

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.