Home > front end >  laravel 9 (how can i make this code better..more compact)
laravel 9 (how can i make this code better..more compact)

Time:11-11

I have 3 lists from 3 different stages of a client. I want to list all the clients, but separated by the stages of those clients.

<div >
    <!-- Title and Top Buttons Start -->
    <div >
        <div >
            <!-- Title Start -->
            <div >
            
                <!-- @include('_layout.breadcrumb',['breadcrumbs'=>$breadcrumbs]) -->
            </div>
            <!-- Title End -->
        </div>
    </div>
    <!-- Title and Top Buttons End -->

    <!-- Content Start -->
    <div>
    <div >
                <!-- Buttons Start -->
                <div >
                    <section  id="buttons">
                    
                        <!-- Lista Prospecção  -->
                        
                        <div >                               
                            <h2 >Prospecção</h2>                               
                        </div>
                        <div >
                            <div  data-count="5">
                            @foreach ($clientes->where('etapa', '1') as $cliente) 

                                <div >
                                    <div >
                                        <div >
                                            <div >
                                                <div >
                                                    <div >
                                                        <div>{{$cliente->nome}} </div>
                                                        <div ><a href="https://wa.me/55{{$cliente->contato}}">{{$cliente->contato}}</a></div>
                                                        <div >{{$cliente->mes}}/{{$cliente->ano}}</div>                                                                                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                                           
                                    </div>
                                </div>
                            @endforeach

                            </div>
                        </div>
                        <!-- Fim Lista Prospecção -->
                        <br />
                        <!-- Lista Necessidade do Cliente  -->
                        
                        <div >                               
                            <h2 >Necessidade do Cliente</h2>                               
                        </div>
                        <div >
                            <div  data-count="5">
                            
                            
                            @foreach ($clientes->where('etapa', '2') as $cliente) 
                          
                                <div >
                                    <div >
                                        <div >
                                            <div >
                                                <div >
                                                    <div >
                                                        <div>{{$cliente->nome}} </div>
                                                        <div ><a href="https://wa.me/55{{$cliente->contato}}">{{$cliente->contato}}</a></div>
                                                        <div >{{$cliente->mes}}/{{$cliente->ano}}</div>                                                                                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                                           
                                    </div>
                                </div>
                            @endforeach

                            </div>
                        </div>
                        <!-- Fim Lista Necessidade do Cliente -->
                        <br />
                        <!-- Lista Marcou Consulta  -->
                        
                        <div >                               
                            <h2 >Marcou Consulta</h2>                               
                        </div>
                        <div >
                            <div  data-count="5">
                            @foreach ($clientes->where('etapa', '3') as $cliente) 
                                <div >
                                    <div >
                                        <!-- <div >
                                            <img src="/img/product/small/product-2.webp" alt="alternate text"  />
                                        </div> -->
                                        <div >
                                            <div >
                                                <div >
                                                    <div >
                                                        <div>{{$cliente->nome}} </div>
                                                        <div ><a href="https://wa.me/55{{$cliente->contato}}">{{$cliente->contato}}</a></div>
                                                        <div >{{$cliente->mes}}/{{$cliente->ano}}</div>                                                                                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                                           
                                    </div>
                                </div>
                            @endforeach

                            </div>
                        </div>
                        <!-- Fim Lista Marcou Consulta -->
                        <br />
                        <!-- Lista Apresentou Proposta  -->
                        
                        <div >                               
                            <h2 >Apresentou Proposta</h2>                               
                        </div>
                        <div >
                            <div  data-count="5">
                            @foreach ($clientes->where('etapa', '4') as $cliente) 
                                <div >
                                    <div >
                                        <!-- <div >
                                            <img src="/img/product/small/product-2.webp" alt="alternate text"  />
                                        </div> -->
                                        <div >
                                            <div >
                                                <div >
                                                    <div >
                                                        <div>{{$cliente->nome}} </div>
                                                        <div ><a href="https://wa.me/55{{$cliente->contato}}">{{$cliente->contato}}</a></div>
                                                        <div >{{$cliente->mes}}/{{$cliente->ano}}</div>                                                                                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                                          
                                    </div>
                                </div>
                            @endforeach

                            </div>
                        </div>
                        <!-- Fim Lista Apresentou Proposta -->
                        <br />
                    </section>
                </div>
                <!-- Buttons End -->
            </div>                 
    </div>
    <!-- Content End -->
</div>

The code is working.

@foreach ($clientes->where('etapa', '1') as $cliente) 
@endforeach

This is the main loop. I have to make a foreach inside this foreach? Showing each "etapa" (stage) that my client is?

CodePudding user response:

    <div >
    <!-- Title and Top Buttons Start -->
    <div >
        <div >
            <!-- Title Start -->
            <div >
            
                <!-- @include('_layout.breadcrumb',['breadcrumbs'=>$breadcrumbs]) -->
            </div>
            <!-- Title End -->
        </div>
    </div>
    <!-- Title and Top Buttons End -->

    <!-- Content Start -->
    <div>
    <div >
                <!-- Buttons Start -->
                <div >
                    <section  id="buttons">
                        
                    
                        <!-- Listas  -->
                        
                            @php                                        
                            $etapa = [
                                '1' => 'Prospecção',
                                '2' => 'Necessidade do Cliente',
                                '3' => 'Marcou Consulta',
                                '4' => 'Apresentou Proposta',
                                '5' => 'Negócio Fechado',
                                '6' => 'Negócio Perdido',
                                '7' => 'Oportunidades Futuras'
                            ];                                            
                                                                     
                        @endphp
                        @foreach ($etapa as $keyetapa => $e)

                            <div >                               
                                <h2 >{{ $e }}</h2>                               
                            </div>
                            <div >
                                <div  data-count="5">                                

                            @foreach ($clientes->where('etapa', $keyetapa) as $cliente) 

                                <div >
                                    <div >
                                        <div >
                                            <div >
                                                <div >
                                                    <div >
                                                        <div>{{$cliente->nome}} </div>
                                                        <div ><a href="https://wa.me/55{{$cliente->contato}}">{{$cliente->contato}}</a></div>
                                                        <div >{{$cliente->mes}}/{{$cliente->ano}}</div>                                                                                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                                           
                                    </div>
                                </div>
                            @endforeach  
                        </div>
                    </div>
                    <br />
                        @endforeach
                        
                    </section>
                </div>
                <!-- Buttons End -->
            </div>                 
    </div>
    <!-- Content End -->
</div>
  • Related