Did anyone has issues with env variables? For some reason, helper env('VARIABLE') returns null every time I use it. It happened very unexpectedly and I dont really know the reason. Restarting the apache/IDE/computer does not work.
Run those of command
composer dump-autoload
php artisan cache:clear
php artisan config:clear
php artisan view:clear
Now try to read
$value = env('VARIABLE_NAME');
if not working till now then,
Try another syntax to read env variable.
$value=getenv('VARIABLE_NAME');
The solution is simple, but neither the IDE nor the debugger says anything about it. It just returns null. When you use php artisan config:cache, according to the documentation:
If you execute php artisan config:cachecommand during your deployment process, you should be sure that you are only calling the env() function from within your configuration files.
Obviously I have env variables outside the config files, so after caching I was not able to use it outside anymore. The php artisan config:clear puts it back to work.
What I've found more about the usage of env, that it should be used only within config files. You can access env variables from the rest of the project using other helper method config(). Be sure to assign it to another key in config file, e.g. 'key' => env('CACHE_DRIVER')
What is more, you have to remember to run php artisan config:cache each time you will change .env file. Laravel will not load the new values, until it's cached. If it's not cached, no need to do it.
please use this its work for me use git bash or cmd and past this command
$ rm bootstrap/cache/config.php
this command clear cache folder
Just run
php artisan config:clear
It solved my issue.
In my case, it's just because I'm using php artisan serve, just restart it, the server command may read the env and keep at the startup time.
Related
I tried to install Vanilo E-Commerce onto my existing application which clashed with a lot of my migrations thus I want to now remove it.
I tried to run
composer remove vanilo/framework
Which removed everything but then gives me the error:
Class 'Konekt\AppShell\Providers\ModuleServiceProvider' not found
Whenever I attempt to do anything. I believe this comes from when you do:
php artisan vendor:publish --provider="Konekt\Concord\ConcordServiceProvider" --tag=config
How can I remove this provider? I cannot find it in my config/app.php or anywhere else.
You have to delete config/concord.php since that is where Konekt\AppShell\Providers\ModuleServiceProvider is referenced
Try to clear config cache:
php artisan config:cache (clears and caches it again, you can also use clear if I remember it correctly)
You can also try to clear the application cache:
php artisan cache:clear
I have a laravel project but when I use the command "php artisan serve" and type the url: http://127.0.0.1:8000/ , its just keep on loading without output nor error appear.
I solved this by running this command instead of PHP artisan serve.
php -S 127.0.0.1:8000 -t public/
Then try to load again 127.0.0.1:8000 in your browser.
Try disabling your anti-virus or check your firewall.
I disabled my Avast anti-virus and it's working fine for me now.
The port 8000 might be used by other in your computer. Try to change port by running in your project in cmd:
php artisan serve --port=1000
then type http://127.0.0.1:1000/ on your browser.
Run commands
php artisan config:clear
php artisan config:cache
Even after completing these steps, if Laravel is still showing error, check your_project/storage/logs/laravel.log.
Try these three commands for clearing cache config:
php artisan config:cache // clear config cache
php artisan config:clear // clear config cache
php artisan cache:clear // clear cache
php artisan optimize // To reoptimize the class loader
php artisan route:cache // clear route cache
php artisan view:clear // clear view cache
It sometimes happen because of too many redirection and also sometime because of middleware . so see your whole flow for that page.
Also see your cdn which included in your page because it take too many time if you have too many cdn and your connection is slow. And also try to clear all cache.
I experienced this problem also when I first launched out into Laravel.
Your port 8000 is most likely occupied by another service or program.
Simply go to your terminal where your project is open, and enter the following command
php artisan serve --port=1000
Then, return to your browser and enter the address, replacing 8000 with 1000, as in
127.0.0.1:1000
This worked for me.
There are several issues may be possible for that.
You have used CDN JS and CSS
Check you route/web.php
Check you log error log file storage/logs/laravel.log
Check above points this will sure give you positive result.
In my case I uninstalled Xampp and reinstalled it(I'm assuming you are using Xampp too).It worked for me.
If you are using xampp
just restart Apache and MySql
To be able to run Browser tests directly in my IDE (without using the artisan dusk command), I want to run php artisan serve --env=dusk.local. While it indeed starts the local PHP server, it uses the wrong database. It uses the database specified in .env not the one in .env.dusk.local.
I ran php artisan cache:clear thousands of times, but it doesn't change anything.
Running things like php artisan migrate --env=... works.
Is there a way to achieve my goal without needing to rename my .env.dusk.local file to .env before each test?
This is a bug in Laravel 5.8: https://github.com/laravel/framework/issues/27828
There is currently no solution (other than downgrading to Laravel 5.7).
It has been fixed in the latest release 5.8.7.
I found the problem
if i restart php artisan serve the changed values are applied. this is
the norm? how can i solve this
I created a router where I output config information
I'm trying to change value from .env file, for example APP_NAME, from APP_NAME="Nuxt + Laravel" to APP_NAME="test" but the change is not displayed on the page!(of course I reloaded the page 😊)
I was trying to look through php artisan tinker
It works!
But my config remains the same. I can not solve this problem for a week now.
I cleared the cache!!! I tried php artisan cache:clear, php artisan config:clear (i tried all command for cache)
CACHE_DRIVER=file
I deleted files bootsprap/cache/*, storage/framework/cache/*.
I tried everything!!!
I have this project on the github: https://github.com/iliyaZelenko/laravel-nuxt.
Please help me, I want my project to be used by other people.
I'm trying to run Laravel Dusk and I need to use a test database. When I check the screenshot it says that the database doesn't exist. Problem is that is the database defined on .env and not the one on .env.dusk ... I've tried to rename the file to .env.dusk.local and still no luck. What am I doing wrong?
Try clearing your cache? I remember having similar issues when I first started using dusk.
php artisan cache:clear
I got the same problem. Lately I figured out that the .env file is being cached before dusk start.
I resolved it by adding
$this->artisan('config:cache');
into the createApplication() function in CreateApplication.php. It works :)
But then, if I finished the dusk test, I must run
php artisan config:cache
to get the original server running.
Edit:
later I tried simply call the
php artisan config:clear
also prevent the application caching the env variable. (Much simpler and faster)
I was able to get this to work by following these steps:
Remove .env.testing
Run php artisan dusk (This will create phpunit.dusk.xml).
Add the following to the end of this newly created file
<phpunit>
...
<php>
<server name="APP_ENV" value="local"/>
</php>
</phpunit>
You can now restore .env.testing which can still be used for phpunit testing.
ORIGINAL ANSWER
I found that if you remove .env.testing it then uses .env.dusk.local. It seems that .env.testing always take precedence.
This does not solve the problem of using a separate .env for unit tests & dusk; which is useful when running unit tests in memory and dusk tests using sqlite.
Same issue... The problem is you forgot to create config cache file for your testing env so dusk will use your current local config cache file instead. Here is the fix:
1/ duplicate .env to .env.dusk.testing and edit the following:
APP_ENV=testing
DB_DATABASE=halfwish_test #I use different MYSQL database for testing.
2/ run this cmd:
$ php artisan config:cache --env=dusk.testing && php artisan clear //clear compiled services and packages files and cache config file.
$ php artisan migrate:fresh --env=dusk.testing && php artisan seed --env=dusk.testing //this is migrating and seeding demo data to DB.
Now you can run php artisan dusk.