How to return only two value in a loop

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to return only two value in a loop



The app is all about scoring video uploaded online, with adjudicators of different category.



I have in my controller


$watched = Upload::with('scoresheet')->get();



There is a reletionship between upload and scoresheet.
In my controller, I am using "with" to grab the relationship eagerly, so that I can get who scored a video.



Now I am trying to loop through and displaying scored or unscored with the ifesle statement if they satisfy this condition


ifesle


@foreach($watched as $scoredvideo)
@foreach($scoredvideo->scoresheet as $seen)
@if($seen->user_id == Auth::user()->id && $seen->upload_id == $video->id)
Scored
@else
Not Scored
@endif
@endforeach
@endforeach



but, it kept on returning the message of the numbers of video that have been scored.



See below



Here, three videos have been scored.



I tried using break, it only display the true value which is 'scored' and terminate the loop.



How can I solve this this?





how to get $ video-> id?
– Faris Dewantoro
Aug 6 at 8:39





can you display the error?
– Faris Dewantoro
Aug 6 at 8:39




2 Answers
2



Your question is not very clear but if I understand it correctly you are trying to know whether a logged in user has scored the video or not. I would do it something like this.


@foreach($videos as $video)

//render the video object however you want in your view

//and use this if to know if the logged in user has already scored the video
@if($video->Scoresheet()->where('user_id', Auth::user()->id)->exists())
scored
@else
Not Scored

@endforeach


foreach (array_slice($watched , 0, 2) as $scoredvideo )
//do something





Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you've made.
– Tim Diekmann
Aug 6 at 9:51






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS