Count in PHP via variable value

-2

I'm having trouble with something relatively simple, but it's causing me a headache because I always get a mistake.

In a precise application pick up the amount of open classes coming from the Crud de Turmas. It was to show the amount of open-class classes that are 6, but I'm not able to implement this to appear on the dashboard. I can only set the value manually, in this example I put 40, can anyone help me?

Screen:

Andhere'sthesnippetofcode:

@extends('layouts.app')@section('content')<divclass="row">
        <div class="col-lg-6 col-xs-12">
          <!-- small box -->
          <div class="small-box bg-yellow">
            <div class="inner">
              <h3>40</h3>

              <p>Turmas Abertas</p>
            </div>
            <div class="icon">
              <i class="ion ion-person-add"></i>
            </div>
            <a href="treinamentos" class="small-box-footer">Veja Mais <i class="fa fa-arrow-circle-right"></i></a>
          </div>
    </div>

<div class="row">
<div class="col-md-6">
            <div class="panel panel-default">

                <div class="panel-heading">Turmas com status <strong>Aberta</strong></div>

                <div class="panel-body table-responsive">
                    <table class="table table-bordered table-striped ajaxTable">
                        <thead>
                        <tr>
                            <th><center> @lang('Nome do Treinamento')</th> 
                            <th><center> @lang('Data de Inicio')</th> 
                            <th><center> @lang('Data de Conclusão ')</th> 
                            <th><center> @lang('Situação da Turma')</th> 
                            <th>Ações<center>&nbsp;</th>
                        </tr>
                        </thead>
                        @foreach($treinamentos as $treinamento)
                            @if($treinamento->situacao_turma == "Aberta")
                            <tr>

                                <td><center> ? </td>
                                <td><center>{{ $treinamento->data_inicio }} </td> 
                                <td><center>{{ $treinamento->data_conclusao }} </td> 
                                <td><center>{{ $treinamento->situacao_turma  }} </td>
                                <td><center>

                                    @can('treinamento_view')
                                    <a href="{{ route('admin.treinamentos.show',[$treinamento->id]) }}" class="btn btn-xs btn-primary">@lang('quickadmin.qa_view')</a>
                                    @endcan
                                </td>
                            </tr>
                        @endif
                        @endforeach
                    </table>
                </div>
            </div>
</div>

@endsection

Image:

CONTROLLER CODE:

<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $cargos = \App\Cargo::latest()->get(); 
        $setores = \App\Setore::latest()->get(); 
        $turmas = \App\Turma::latest()->get(); 
        $treinamentos = \App\Treinamento::latest()->get(); 

        return view('home', compact( 'cargos', 'setores', 'turmas', 'treinamentos' ));
    }
}
    
asked by anonymous 15.12.2018 / 00:26

1 answer

1

After clarifying doubts, I came to this answer:

On your Controller you will count to get the total:

public function index()
    {

        $cargos = \App\Cargo::latest()->get(); 
        $setores = \App\Setore::latest()->get(); 
        $turmas = \App\Turma::latest()->get(); 
        $treinamentos = \App\Treinamento::latest()->get(); 
          $total = 0;
          foreach($treinamentos as $treinamento)
            if($treinamento->situacao_turma == "Aberta") $total++;

        return view('home', compact( 'cargos', 'setores', 'turmas', 'treinamentos', 'total' ));
    }

Then just insert it into the view:

<h3>{{ $total }}</h3>

The rest of the code is the same.

    
15.12.2018 / 02:05