Blade view Support

Asked

Viewed 97 times

-1

There is some way to add a Count in the Blade. For in the interaction it returns 1 1 0 0

  @forelse($surveys as $survey)

              <p> @forelse($survey->options as $option)
                    {{ $option->users->count()}}
                  @empty
                    Nenhum voto até o momento
                  @endforelse


      @empty

      @endforelse

On the controller it’s like this

    public function index()
{

    $user = $this->user->find(auth()->user()->id);
    $surveys = Survey::whereHas('options', function ($query) use ($user) {
        $query->where('user_id', '=', $user->id );
    })->get();


   return view("painel.usuario.index",compact('surveys'));
}

A Survey has several options. One option has several user. A user can choose several options, but from different polls. An option belongs only to a sruvey.

exit inserir a descrição da imagem aqui

In case it has 2 votes. but it brings one to one. for each option has only one users

  • Hi Fabio, please put more information in the question; 1. what the variable $Survey has?

  • the variable Survey has several options and each option can have several users

  • but the options belong to only one Survey

  • the controller that returns that view looks like this $Surveys = Survey::whereHas('options', Function ($query) use ($user) { $query->Where('user_id', '=', $user->id ); })->get(); Return view("dashboard.usuario.index",Compact('Surveys'));

  • Check a relationship of type hasManyThrough https://laravel.com/docs/5.8/eloquent-relationships#has-Many-through

  • It works even pivoting the table option_users ? Why I tried, it didn’t work.

  • Not one for many, one for many ?

  • What are these options?

Show 3 more comments

1 answer

0

@if (count($records) === 1)
    I have one record!
@elseif (count($records) > 1)
    I have multiple records!
@else
    I don't have any records!
@endif
  • He keeps bringing one to a grave, he’d already done it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.