Hi, I have created a Composer named Single with the content:
<?php
namespace App\View\Composers;
use Roots\Acorn\View\Composer;
class Single extends Composer
{
/**
* List of views served by this composer.
*
* @var array
*/
protected static $views = [
'single',
];
/**
* Data to be passed to view before rendering, but after merging.
*
* @return array
*/
public function with()
{
return [
'all_user' => $this->get_all_users_count()
];
}
public function get_all_users_count(){
global $wpdb;
return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users");
}
}
During the loading of the single.blade.php page, there is a duplication of the query ‘SELECT COUNT(*) FROM $wpdb->users’. It seems like the with() method is being executed twice.
Why is this happening? Please help. Thank you in advance.