I was trying to declare a static var, but always is null, I try several combinations and ways without luck. I'm trying to store a var with some data, but I really don't want to reprocess, If already was processed one time.
class PackingController extends Controller
{
protected static $i;
function Process(Request $request)
{
$r = new packing();
$v = $r->customer('data','data');
$items = $this->startProcess($v,false);
return \View::make('list/print',compact('items'));
}
private function startProcess($dbitems, $ajust=false)
{
//Some logic
self::$i = $items;
return $items;
}
function printPdf()
{
$items = self::$i;
//shows null:
dd($items);
}
}
What's is wrong?
Update: I try with singleton without luck.
namespace App\Helper;
class Items
{
private static $_items;
private static $inst;
public function setItems($value)
{
self::$_items = $value;
}
public function getItems()
{
return self::$_items;
}
public static function Instance()
{
if (self::$inst == null) {
self::$inst = new Items();
}
return self::$inst;
}
private function __clone()
{
}
private function __construct()
{
}
}
With singleton, still null, Also try with a single value, instead of variable, without luck
class PackingController extends Controller
{
protected static $i;
function GetPackings()
{
$s = sales::with('Customer')->where('salestype','=','3')->take(1000)->orderBy('receiptdaterequested','desc')->pluck('salesid','salesid');
$p = pack::distinct('APPACKINGGROUPID')->pluck('APPACKINGGROUPID','APPACKINGGROUPID')->all();
return \View::make('listas/index',compact('p','s'));
}
function Process(Request $request)
{
$r = new packing();
$v = $r->customer('Mexico','PVE0111998');
$items = $this->startProcess($v,false);
return \View::make('listas/print',compact('items'));
}
private function startProcess($dbitems, $ajust=false)
{
$bultos = 1;
$items = array();
foreach ($dbitems as $dbitem)
{
//Some process
$items[]=$item;
}
$s = Items::Instance();
if (count($items) > 0 ) {
$s->setItems($items);
}
return $items;
}
function printPdf()
{
$s = Items::Instance();
$s->getItems();
dd($s->getItems());
}
}