I have a simple foreach block in my view, like below.
@foreach ($teams as $key => $team)
{{ str_ordinal($key + 1) }}
@endforeach
Right now I'm displaying the key, although it isn't exactly accurate. Here's an image: https://i.imgur.com/0pvUKF5.png
How can I display the actual position of the current iteration? I order by my teams
collection but I'm not sure how I get the position of the current interation in that loop?
You can apply array_values
to your data before passing to template:
array_values($teams);
Or, according to this https://laravel.com/docs/5.6/blade#the-loop-variable, you can use special $loop
variable. I suppose you need $loop->iteration
property (it starts with 1
) or $loop->index
(starts with 0
):
@foreach ($teams as $key => $team)
{{ $loop->iteration }}
@endforeach
You can use $loop->index
to get the index
Use a for
loop instead of a foreach
. You will get them in order.
$count = count($teams) ;
for($i=1;$i<=$count;$i++) {
// your code here using $i as the position
}
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
i can't get any data from php-phantom it's not working with me i found this error in php_log file when i tried get source page using php-phantom and this is the Full code
I am trying to use Laravel for websocket server with orchid/socket pakageIt works fine with running following command on the local :
I'm getting an XML response that I cannot parseHere's the thing:
I am working on restfull api's for mobile app developmentI am returning an php array in json which is like,