laravel env method get different value when code not change ? - laravel

I'm new beginner of laravel.I want use Helpers to get environment value using env method.
class Helpers {
public static function somefunc(){
var_dump(env('QINIU_BUCKET_DOMAIN'));exit;
}
}
Then strange thing happed.When I opened chrome-dev-tool (F12),I got nothing. Then I closed chrome-dev-tool,I got what I want. Is anything wrong? Anybody can help me? :)

Laravel's .env manages configuration for the server side environment.
So, you opening and closing Chrome Dev Tools has nothing to do with this!
You might have changed something in the server environment.
So restarting your server might help.
Check the documentation - http://laravel.com/docs/5.1#configuration

Related

cannot access Component controller variables inside the component view

I have been running into this very weird issue with Laravel.
I had a problem where one of my component views was not able to read the variables defined in its class. It was kind of strange because I have several components running in my project and they all worked fine, except for this one.
So I created a fresh Laravel project to test some things out (Wanted to check if the problem was on my end, maybe I somehow messed up the project files).
I created a new component on a blank project using php artisan make:component top_nav
pre function basically is used as print_r which is in helper.php
Then I simply added a sql_data variable to the class component like so:
i tried many thing as much as i can do but still i can't access that variable
also clear cache of view
of laravel
change name of components but still can't work
kindly help me..........
you should
return view('components.top_nav', ['sql_data' => $sql_data]);
you are not passing the variable to the view
composer install
npm install && npm run dev
php artisan optimize
I just copied your screenshots into a new laravel installation and ran it with no problems.
Try setting the public property with a default value:
public $sql_data = 'testing'
If you try the above and still have issues, I'd like to confirm the output of AdminLogin::all().
PS:
TopNav instead of top_nav Class name please.

CodeIgniter 4 - Refused to get unsafe header "Debugbar-Time"

I just installed CodeIgniter 4, configured the .env file to "development" and did also set the base url. For some strange reason, when I load a controller I get this error concernig the CI debug bar:
How can I solve this error?
Thanks!
You can try by removing 3rd party js plugins. In my case Paypals checkout.js is causing the issue when ci4 is in development environment. It will be gone when you switch to production
This Answer maybe too late. But I just want to inform to some poeple that have an issue like this. So in my trouble, I just remove some js in my apps. It's work for me.

Replace localhost with my domain in Laravel when in production

I am using SPA (Laravel and Vuejs). When in development, website project worked perfect but when after running npm run production and put it on live server, I got errors saying
Access to Xmlhttprequest at http://localhost:8000/auth_check from origin https://hamariweb.com/auth_check has been blocked by Cors policy.
I have tried different solutions that fixed their problems but not mine. I want to know what is wrong with it and how can I fix it?
Sounds like somewhere in your code you're trying to send a request to http://localhost:8000/auth_check which isn't going to work in prod. You need to find the call to that URL and replace it with a call to the correct URL.
You can create an ENV setting in your .env file like this.
APP_URL=https://hamariweb.com
Then share that env file to your javascript code like this.
MIX_APP_URL="${APP_URL}"
Any ENV settings that start with MIX_ are passed to Javascript and this is passing it the initial APP URL value.
To finally grab the app url in the JS do this:
process.env.MIX_APP_URL
You can even assign the entire env settings globally like this.
if(process && process.env){
window.env = process.env;
}
Any .env MIX_ variables will be available in window.env at that point and in your SPA you'll be able to make the URL or any other variable configurable based on environment.

Cannot access environment variable during jQuery AJAX POST

In my .env file I have a custom entry SECRET_FILE_NAME=mysecretfile.txt. Somewhere in my controller I need to access mysecretfile.txt, and I obtain its path as follows:
base_path(env('SECRET_FILE_NAME'))
This returns the correct path:
"C:\laragon\www\myproject\mysecretfile.txt"
However, during an AJAX POST call the result is
"C:\laragon\www\myproject"
It turns out that env('SECRET_FILE_NAME') returns "mysecretfile.txt" during a regular POST (tested through Postman Chrome extension), but it returns null during AJAX POST.
How is it possible? Both are POST-ing to the same URL, same controller action. Is this a caching issue? I tried php artisan config:clear but nothing changed.
On a side note, do you think it's ok to access ENV variables directly from .env file? Or should I instead put them in app/config/services.php and access them though
config('services.filenames.mysecretfile')
Thanks!
EDIT
With the help of #shalvah, I figured that putting a reference to the environment variable in config/services.php fixed the problem:
'secret_filenames' => [
'my_secret_file' => env('SECRET_FILE_NAME')
],
The entry still remains in the .env file: SECRET_FILE_NAME=mysecretfile.txt. But now I can use it as follows:
config('services.secret_filenames.my_secret_file')
This solves my problem; however I am curious why calling env('SECRET_FILE_NAME') directly results in a null value? Is this caching issue? Also, does it make sense to store this kind of info in services.php?
EDIT 2
Just stumbled upon a discussion on Laracasts that might shed some light on this.

Laravel's pretty var_dump(), dd(), not working anymore

For some reason laravel's dd() function decided to stop functioning. I have no idea how this happened. I tried composer update already but I'm not sure what else can be going on. The debug key is set to true in the config.
Where should I look to solve this problem? I'm using Laravel 4.2.16
NOTE:
dd() now simply functions as var_dump(), it doesn't prettify it anymore
Solved it. I loaded my vagrant machine with the wrong config and was running hhvm instead of regular php-fpm. Hence xdebug, which handles the pretty dd(), was not being loaded. I reloaded my box with the correct settings (without hhvm and hack) and everything started working again
Is dd the only Laravel helper function that doesn't work? If not then check the contents of vendor/composer/autoload_files.php. The laravel support helpers are loaded here. If the other helper functions are fine you can check the contents of laravel/framework/src/Illuminate/Support/helpers.php to see what's going on - this is where the function is created.

Resources