I
I
IvanKalinin2015-03-01 10:42:45
Laravel
IvanKalinin, 2015-03-01 10:42:45

Why does validation in Laravel only happen the first time?

All the best.
There is a table with recipes, a table with users and a "favorite" table, which contains the user id and recipe id.
The main page displays the actual recipes themselves
in the index page template

@foreach ($recipeCards as $recipeCard)
    @include('template.recipePreview')
@endforeach

and in the plug-in template of the recipe itself, such a check is carried out
@if (Auth::check())
                <?php $count = Favorite::where('dishId', '=', $recipeCard->id)->where('id', '=', Auth::user()->id)->count(); ?>
                @if ($count <> 0)
                    <li class="favorite black"></li>
                @else
                    <li class="favorite gray"></li>
                @endif
            @endif

those. if the recipe is in the user's favorites, a black icon is placed, if not, then a gray one.
For some reason, $count == 1 only on the condition that the first displayed recipe is in the favorites and only for him.
In other cases, $count == 0. Why - so far it has not been possible to understand.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andreyqin, 2015-03-01
@IvanKalinin

Maybe because you compare Auth::user()->id with id, but you need with some user_id?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question