-1

i'm new to laravel and i want o bring a array value to my list

i think its easy to solve this

can you guys please help

<i data-acorn-icon="category"></i>
<select class="form-control" id="mes" name="mes" data-placeholder="Mês">
@php
$mes = [
    "1" => "Janeiro",
    "2" => "Fevereiro",
    "3" => "Março",
    "3" => "Abril",
    "3" => "Maio",
    "3" => "Junho",
    "3" => "Julho",
    "3" => "Agosto",
    "3" => "Setembro",
    "3" => "Outubro",
    "3" => "Novembro",
    "3" => "Dezembro"];

$valormes = $cliente->mes ;
@endphp
<option value="{{ $cliente->mes }}" selected>@php print_r($mes[$valormes]) @endphp </option>
    <option value="1">Janeiro</option>
    <option value="2">Fevereiro</option>
    <option value="3">Março</option>
    <option value="4">Abril</option>
    <option value="5">Maio</option>
    <option value="6">Junho</option>
    <option value="7">Julho</option>
    <option value="8">Agosto</option>
    <option value="9">Setembro</option>
    <option value="10">Outubro</option>
    <option value="11">Novembro</option>
    <option value="12">Dezembro</option>
</select>
</div>

this is the part with the problem <option value="{{ $cliente->mes }}" selected>@php print_r($mes[$valormes]) @endphp </option> doesnt bring the value.. getting error screen always

3

1 Answer 1

0

It will solve your problem.

                <i data-acorn-icon="category"></i>
                <select class="form-control" id="mes" name="mes" data-placeholder="Mês">
                @php
                    $mes = [
                        '1' => 'Janeiro',
                        '2' => 'Fevereiro',
                        '3' => 'Março',
                        '4' => 'Abril',
                        '5' => 'Maio',
                        '6' => 'Junho',
                        '7' => 'Julho',
                        '8' => 'Agosto',
                        '9' => 'Setembro',
                        '10' => 'Outubro',
                        '11' => 'Novembro',
                        '12' => 'Dezembro',
                    ];
                    
                    $valormes = $cliente->mes;
                @endphp
                @foreach ($mes as $key => $m)
                    @if ($key == $valormes)
                        <option value="{{ $key }}" selected>{{ $m }}</option>
                    @else
                        <option value="{{ $key }}">{{ $m }}</option>
                    @endif
                @endforeach
               </select>
             </div>
Sign up to request clarification or add additional context in comments.

6 Comments

we're almost there.. showed all values except the "selected" $m
Check this out, type @dd($cliente->mes) anywhere on the page and tell what it returns.
its returning the right number of the specific month i've used print_r either.. and its showing the number too
Then all you have to do is check the $key I'm editing the code and try again.
perfect my friend, you are the best !
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.