I am using Laravel 6 with visual studio code. The last successfully command i run is given below with their out put.
php artisan config:clear Configuration cache cleared!
But after that, whatever command i do execute it gives me an error
In AbstractVariables.php line 54: Expected name to be a string.
I have tried to execute given below commands, but all of these ends up with above mentioned error.
composer update php artisan serve php artisan config:clear php artisan cache:clear php artisan route:clear
I have tried to find out file named “AbstractVariables.php” and i did find it in given below directory
vendorvlucasphpdotenvsrcEnvironment
I have tried to read what is code is given on line 54 of file named “AbstractVariables.php”
public function get($name){ if (!is_string($name)) { throw new InvalidArgumentException('Expected name to be a string.'); } return $this->getInternal($name); }
And the comments above this function is…
* Get an environment variable. * @param string $name * @throws InvalidArgumentException * @return string|null
So, it means it is searching environment variable some where and it is not able to find string there.
.env
file in my profile has all variables name.
Now, I am not able to understand what else is missing, I have done a lot of search on google but didn’t find any thing in this regard.
Advertisement
Answer
This problem occurred when I configured spatie/laravel-analytics to fetch google analytics data to display in admin panel of website.
In order to make it functional it was required to add 'view_id' => env('ANALYTICS_VIEW_ID')
in config/analytics.php
file.
What mistake was done?
In config/analytics.php
file I added view id without single quote mark which was wrong. Example is given below….
'view_id' => 123456789,
After that whenever I hit follow commands i get error
php artisan config:clear php artisan cache:clear
Error is given below…
In AbstractVariables.php line 54: Expected name to be a string.
How I solved issue?
I have updated config/analytics.php
as per documentation and changed it like given below…
'view_id' => env('ANALYTICS_VIEW_ID')
And in .env
file added environment variable ANALYTICS_VIEW_ID
ANALYTICS_VIEW_ID=216007652
After that both commands php artisan config:clear
and php artisan cache:clear
worked perfectly.