Closed mitoop closed 6 years ago
Hi @mitoop ,
You need to reset these static variables before every request by yourself. You can write your reset logics in a service provider and add it to providers
in swoole_http.php
.
Hi @albertcht I had tried. But it didn't work. I will make an another try. Thanks.
Hi @albertcht Excuse me. Is there any good practice to reset the class static varible?
Hi @mitoop ,
I think resetting static variables in service provider should do the trick. Do you mind providing more details about your implementation in your service provider?
Hi @albertcht
class Nova
{
use AuthorizesRequests;
/**
* The registered resource names.
*
* @var array
*/
public static $resources = [];
/**
* An index of resource names keyed by the model name.
*
* @var array
*/
public static $resourcesByModel = [];
/**
* The callback used to create new users via the CLI.
*
* @var \Closure
*/
public static $createUserCallback;
....
In the code, it's used directly. like $resources
. I tried in service provider and write a resetter to make the variable equel its original value. But not works.
Is it clear about what I say?
Hi @mitoop ,
Can you paste the code of your service provider below?
Hi, @albertcht In swoole_http.php
'providers' => [
Illuminate\Pagination\PaginationServiceProvider::class,
Bugsnag\BugsnagLaravel\BugsnagServiceProvider::class,
Clockwork\Support\Laravel\ClockworkServiceProvider::class,
App\Providers\NovaServiceProvider::class, // The service provider
],
the boot and register:
public function boot()
{
$this->routes();
Nova::serving(function (ServingNova $event) {
$this->authorization();
$this->resources();
Nova::cards($this->cards());
Nova::tools($this->tools());
});
}
public function register()
{
//
}
In the service provider, it use Nova
directly.
The Nova
class contains some static class varible.
In the Nova
class
/**
* Register the given resources.
*
* @param array $resources
* @return static
*/
public static function resources(array $resources)
{
static::$resources = array_merge(static::$resources, $resources);
return new static;
}
It like this, so static::$resources
array items repeat when another request coming.
Hi @mitoop ,
What if you reset static $resources
property directly like:
public function boot()
{
Nova::$resources = [];
}
Hi @albertcht
I tried and Now I find some clue, It relates to many class
, Tomorrow I will do more debugging. Thanks your time.
Hi @mitoop ,
What if you reset static
$resources
property directly like:public function boot() { Nova::$resources = []; }
not work well
Did you solved this @zacksleo ?
not yet
Hi, albertcht, my env is
I use laravel nova, and in the nova source code, it use class static variable, how can i reset it? Thanks