X
X
x-comzbk2017-05-11 20:45:50
HTML
x-comzbk, 2017-05-11 20:45:50

Is it possible to write data to a variable in a foreach loop?

I’ll give an example code right away (this is a Blade template in Laravel):

@foreach ($todos as $todo)
                        @if ($todo->public == 1)
                            @if ($todo->status == 1)
                                <div class="panel panel-success">
                            @else
                                <div class="panel panel-danger">
                            @endif
                            <div class="panel-heading">
                                <h3 class="text-center" style="font-style: italic;"> {{ $todo->title}} </h3>

                                @foreach ($profiles as $profile)
                                    @if ($profile->id == $todo->user_id)
                                        <p><span class="fw400">Исполнитель:</span> {{ $profile->name }} </p>
                                    @else 
                                        <p><span class="fw400">Исполнитель не найден</span></p>
                                    @endif
                                @endforeach
                                <span>
                                    <span class="fw400">Начало:</span>
                                    {{$todo->created_at}}
                                </span>
                                <span class="fl-right">
                                    <span class="fw400">Время последнего обновления:</span>
                                    {{$todo->updated_at}}
                                </span>
                            </div>
                            <div class="panel-body">
                                <h5 class="text-center"> {{ $todo->description}} </h5>
                                <p class="text-justify"> {{ str_limit($todo->content, 250) }}</p>
                                <a href="/{{$todo->id}}" class="btn btn-primary fl-right">читать полностью</a>
                            </div>
                            </div>
                        @else @break
                        @endif
                    @endforeach

such a question in this piece of the template:
@foreach ($profiles as $profile)
                                    @if ($profile->id == $todo->user_id)
                                        <p><span class="fw400">Исполнитель:</span> {{ $profile->name }} </p>

can I write the Executor to a separate variable to use outside of the loop!?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pantagruel964, 2017-05-11
@x-comzbk

@php ($user = $profile->user_id)
or

@php
$user = $profile->user_id
@endphp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question