L
L
LP-DIMAN2016-01-11 13:39:03
Laravel
LP-DIMAN, 2016-01-11 13:39:03

What is the correct way to output data from a nested foreach loop?

There is a function:

//Получаем  список клиентов и их предпочтения
  protected  function get_clients()
  {
    $result = DB::select("SELECT * FROM users as u left JOIN clients2adverts as c on u.id = c.id_client 
      left JOIN adverts as a ON c.id_adverts = a.id_realty
          WHERE c.lead = 1 and u.activated = 1 or u.id_role = 2");
    return $result;
  }

part of Vyukha
<h3>Клиенты</h3><br>

            @foreach($clients as $client)
             <div class="table table-bordered">
                <strong>ФИО</strong><br>
                {{$client->surname}} {{$client->name}} {{$client->patronymic}}<br>
                <strong>Предпочтения</strong><br>
                <p>
               Название:{{$client->title}} <br>
               Город: {{$client->city}} <br>
                Количество комнат:{{$client->quantity_room}} <br>
               Описание: {{$client->description}} <br>
               Цена: {{$client->price}}

                </p>
                <strong> Контакты </strong><br>
                {{$client->phone}}
               </div>

            @endforeach

Here is what is displayed on the screen
84b506a952c3486fa619e60313d3f68d.png
How do I make sure that the client is not duplicated, and in the preferences all the client's ads are listed. That is, in my case, there should be one Slyusar Maxim, and preferences - 2 ads. I understand that I need to somehow make nested foreach

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Perin, 2016-01-11
@LP-DIMAN

We take a one-to-many connection, get {{$client->obyavleniya}} in the view and iterate through foreach. By the way, mutators can display the full name of one variable.

E
Eugene, 2016-01-11
@Nc_Soft

https://laravel.com/docs/5.2/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question