{!! Form::select('name', $names) !!}
Here $names is my array and it comes from controller.
$names = ['1'=>'John','2'=>'Patric','3'=>'Deny'];
Actually i want it from .env file.
I got a single variable from .env file but i don't have any idea to get an array from it.
If you use Dotenv/env() there is no way you can get an array just by calling env(VAR). You can add separators to your values in .env and then explode it.
You could also use a config .php file and define your array there then return the desired value defined via .env
Is not possible to retrieve an array from the .env file, but, you can retrieve one from the config settings.
To do this you can create a file inside the /config directory and get its values with \Config::get(). Example:
You create a file named custom.php inside the config directory, and inside of the file you write the following.
return [
'modules' => [
// Array of Modules
]
];
You can retrieve the modules array doing \Config::get('custom.modules').
Related
I have created a config file named email.php inside application/config folder. Now I want to assign my variable $email_config to all the indexes of the $config variable inside my email.php config file.
I have tried to use $email_config = $this->config->config; but this will get all the indexes values of $config variable from every config files under the config folder..I don't want that, I only want the indexes values inside my email.php file
Inside my .env I got these two
ATLAS_RELEASES=null
ATLAS_DOWNLOAD=null
Inside my own config file I have this
'releases_url' => env('ATLAS_RELEASES', $baseUrl . 'atlas/raw/master/releases.json'),
'download_url' => env('ATLAS_DOWNLOAD', $baseUrl . 'atlas/releases/download'),
Once some code runs, that uses
$relasesUrl = config('releases_url');
$downloadUrl = config('download_url');
null is returned instead of the second option, which I've specified in the config file. Since I'm not using .env outside of config files, I wonder why I get this behavior?
The above only works if I remove these two completely from the .env file
ATLAS_RELEASES
ATLAS_DOWNLOAD
Any ideas why this strange behavior happens?
As long as the key exists in the .env file no matter if if is null or no value at all, that one will be used.
https://laravel.com/docs/6.x/configuration#retrieving-environment-configuration
The second value passed to the env function is the "default value". This value will be used if no environment variable exists for the given key.
I cant set a filename with Storage::put in Laravel 5.8
I tried the following:
Storage::put(private/foo/bar , $file, 'private');
This is creating the folder structure with a random generated filename inside. (Like: private/foo/bar/uidjasbknfsdoiruewjnfsdai.pdf)
Storage::put(private/foo/bar/file.pdf , $file, 'private');
This is creating this: private/foo/bar/file.pdf/uidjasbknfsdoiruewjnfsdai.pdf
I expect my own given filename on this private file. The file should not be public.
According to Laravel docs:
If you would not like a file name to be automatically assigned to your stored file, you may use the storeAs method, which receives the path, the file name, and the (optional) disk as its arguments:
$path = $request->file('avatar')->storeAs(
'avatars', $request->user()->id
);
You may also use the putFileAs method on the Storage facade, which will perform the same file manipulation as the example above:
$path = Storage::putFileAs(
'avatars', $request->file('avatar'), $request->user()->id
);
The third argument for the putFileAs is the visibility of the file. If you would like every users can access it, use public instead of $request->user()->id.
You can read more here.
In one of my Laravel based application, I want to include a JSON key file that is currently located in public/key/store.json
Now I want to write a constant in Laravel .env file so that I can access that file anytime I want. So, I write the following line of code:
KEY_FILE='/public/key/store.json'
But it show file path does not exist.
Can anyone tell me what's wrong in my declaration?
you should push your path in your app/config.php not in your .env
I have created a lang file under resources/Lang/en for a module say Room
I am using caffeinated modules
The file itself is Room.php
return [
'deleted' => 'Room has been deleted successfully'
];
Now I am trying to use lang through
trans('room::room.deleted')
but I am not able to get translated string.
Please help me with this
The name of the file in /resource/lang is minuscule.
Eg. room.php
This is the path of variable in first image:
And then, is called this way in blade:
<p>#lang('adminpanel::auth.password')</p>