Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:59:04+00:00 2026-06-17T09:59:04+00:00

In the laravel framework, I have several nested views as follows <mainview> loop @include

  • 0

In the laravel framework, I have several nested views as follows

<mainview>
  loop @include <sub-view>
    loop @include <sub-sub-view>

I would like to keep a counter of just how many sub-sub-views there are. It becomes, in effect, a row counter. I am not sure where to declare/init this variable ($sub-sub-view-counter), and where to increment it along the way. No matter where I put it, it can’t be seen and incremented by every view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:59:05+00:00Added an answer on June 17, 2026 at 9:59 am

    This is maybe a bit of a hack, but unless nothing better comes up…

    You will need either a helper function or an object (easiest way is to put that to the models). For demonstration I chose the object variant, as I believe it’s a bit easier to handle and most of all easier to extend to your needs. Also this implicitly supports multiple counters, as the value is saved per-object (You’d have to jump through a few hoops to get this functionality with a function).

    class Counter
    {
        private $count = 0;
    
        public function inc()
        {
            return ++$this->count;
        }
    }
    

    So for this specific implementation you will have to create it somewhere. You can either put a line like this in your parent view somewhere before including your sub-views, or inject it from PHP with the with() method.

    <?php $counter = new Counter(); ?>
    

    You include the sub-view like usual (remember to use include, not render, to keep the $countervariable) I used a for loop for testing, but you can of course use any variant you want.

    @for($i=0; $i<10; $i++)
        @include('home.sub')
    @endfor
    

    And finally you can just call this in the sub-view

    <span>{{ $counter->inc() }}</span>
    

    You can easily extend this model with a factory to get counter values from anywhere in your application, but for your use case this basic variant should be enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning Laravel framework today. I would like to check for user's
I have an application written with the Laravel PHP framework. My main application listens
I'm developing the frontend for a website using Laravel as php-framework. I have an
I have just recently started working with Laravel. Great framework so far! However I
I am looking at getting into laravel, it looks like an awesome framework,but it
I currently have an application that is built w/ PHP/MySQL using the Laravel Framework
I have an installation of Laravel on Wampserver. The directory is as follows: C:\wamp\www\laravel
Hi I am using Laravel PHP framework on CentOS 6.3. I have PostgreSQL 9.1
I'm trying laravel as a PHP framework, I have already extracted the laravel zip
I am starting to use the Laravel framework, and I have a problem with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.