Passing Variable to Blade Causes increment() to Increment DB Field Twice

Posted 5 months ago by grigelionis

In my Blade file article.blade.php I include another view with a variable.

Blade:

@include('frontend/header', ['page_title' => 'hello' ])

Controller:

public function hitCollector($article_id)
{
    $data["article"] = DB::table('selected_articles')
        ->where('published', 1)
        ->where('id', $article_id)
        ->get();

    $data["article_title"] = "this is title";

    //collecting hit
    DB::table('selected_articles')
        ->where('id', $article_id)
        ->increment('clicks');

    return view('frontend/article', $data);
}

As a result, I am getting DB field 'clicks' increased twice (+2) but not (+1) for given records. I noticed that doubling stops only if I am removing the ['page_title' => 'hello'] part from my Blade inclusion line.

I've checked network tab for any 301, 302 redirects - nothing, just one single 200 response without doubling requests. And yes, no async calls triggered from header, i am running only foreach loope there through passed data.

This is frontend/article.blade.php https://gist.githubusercontent.com/sidmike/73ade4fca5a83d8265c6944c14abd2db/raw/7d7471888c11cd2d1f7697bb8fc8029efd03d78d/gistfile1.txt

And this is frontend/header.blade.php https://gist.githubusercontent.com/sidmike/119f93ae614bfae4f1d86442f6512b84/raw/0fd8d17afb69874f41d5172174978bbd6d65d6ee/header.blade

Any ideas? Bug?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.