@kinshara Yes there is. If you want to use Laravel you can use its singleton method:
app()->singleton('Pages'); // include the namespace
Now whenever you need an instance of Pages simply do:
$var = app('Pages');
Done!
Also, you can make Pages a singleton class on your own which should not be difficult:
class Pages {
protected static $instance;
public static function getInstance()
{
if (is_null(static::$instance)) {
static::$instance = new static();
}
return static::$instance;
}
/**
* Protected constructor to prevent creating a new instance of the
* singleton via the `new` operator.
*/
protected __construct()
{
// your constructor logic here.
}
/**
* Private clone method to prevent cloning of the instance of the singleton instance.
*/
private function __clone()
{
}
/**
* Private unserialize method to prevent unserializing of the singleton instance.
*/
private function __wakeup()
{
}
}
Now simply whenever you need a Pages object:
$var = Pages::getInstance();
Good luck!