i want to seperate my string in constant folder , i create some files to define my constant , but when i want to access them , nothing show in blade , controller and so on , i try to access with this syntax in blade
{{config('constants.welcomeConstants.title')}}
but nothing show in blade , please help me , i seperate all string and now i have no text in my web application
my constant file is :
<?php
return [
'title' => 'test'
];
// /config/constants.php
return [
'welcome' => [
'hello' => 'Hello',
],
];
// Access config value
config('constants.welcome.hello');
just use
php artisan config:clear or php artisan config:cache
Related
I need a little help please :
With Laravel migrations, I like to put the migration in subfolder.
in a testing class, this works :
$this->artisan('migrate:fresh');
But, this does not work :
$this->artisan('migrate:fresh --path=/database/migrations/v1');
Do you have the solution please to specify the path with the tests?
Thank you.
The artisan method takes two parameters ($command, $parameters = []).
To get this to work you'll need to put the options in the parameters array:
$this->artisan('migrate:fresh', [
'--path' => 'database/migrations/v1'
]);
Just an FYI, the same is also true for command arguments e.g.
php artisan make:model Product -m
would be
$this->artisan('make:model', [
'name' => 'Product',
'-m' => true,
]);
I have one file inside config folder lets say: file1
File Location:
config/
---file1.php
I have following code in my file: file1.php
return [
'MASTER_KEY' => ['SUB_KEY1' => 'SOME_VALUE', 'SUB_KEY2' => 'SOME_VALUE', 'SUB_KEY3' => 'SOME_VALUE'],
];
How to access the value from MASTER_KEY of particular SUB_KEY?
Assuming for SUB_KEY2, Try -
config('file1.MASTER_KEY.SUB_KEY2')
Guide
In order to access that value you have 2 choices which are the same at the end:
first one: which use Config refers to the config facade.
use Config;
$myValue = Config::get('file1.MASTER_KEY.SUB_KEY1');
enter code here
second one: using config() helper function which uses Config facade and its only an alternative and easy way to use Config facade.
$myValue = config('file1.MASTER_KEY.SUB_KEY1');
use
config('file1.keyname');
if you have made any changes in config file then it might not work . so after changes in config file you have to run the following two commands .
php artisan config:cache
php artisan config:clear
Make a use Config; in your controller.
In config/file1.php
<?php return [
'ADMIN_NAME' => 'administrator',
'EMP_IMG_PATH' => '../uploads/profile/original',
'EMP_DOC_PATH' => '../uploads/profile/documents', ];
In controller
use Config;
$variable= Config::get('file1.EMP_DOC_PATH');
By this way you can get the variables value from config.
I think this will make something good.
Using the following package: laravel-localization .
I am translating the routes and followed the steps, they all work fine for routes without variables, but i'm stuck on how i should send my variables inside my views.
Link inside my view :
Edit Link
routes.php files inside Lang/fr & Lang/nl
<?php
return [
'account-edit' => "account/wijzig-gegevens/{id}",
];
<?php
return [
'account-edit' => "donnees/modifier-donnees/{id}",
];
Laravel routes file:
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['localize','localeSessionRedirect', 'localizationRedirect' ]
], function()
{
Route::get(LaravelLocalization::transRoute('routes.account-edit'),'AccountController#edit');
});
I tried just adding it inside the route as array like below, but i can't get it working.
Edit Link
Not using the library myself, but according to the code at the github repo, method localizeURL takes in $url and $locale as its parameter, which means that passing in 2nd parameter like you did definitely won't work.
Can you try using method getLocalizedURL?
LaravelLocalization::getLocalizedURL(null, trans('routes.account-edit'), ['id' => $user->id])
Using Laravel 5.2.41
Using following translation package: mcamara/laravel-localization
Link inside my view :
Edit Link
routes.php files inside Lang/fr & Lang/nl
<?php
return [
'account-edit' => "account/wijzig-gegevens/{id}",
];
<?php
return [
'account-edit' => "donnees/modifier-donnees/{id}",
];
Laravel routes file:
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['localize','localeSessionRedirect', 'localizationRedirect' ]
], function()
{
Route::get(LaravelLocalization::transRoute('routes.account-edit'),'AccountController#edit');
});
When i look at the link in my default language (nl) i get the correct link like so:
Edit Link
But when i change my language to french i get following link:
Edit Link
Can't figure out why this is happening
I was looking into the code of that package.
It seems to me if I'm not mistaken, that the logic regarding the translation of URL's is based on the route name, not the route path.
You are using the route path here:
LaravelLocalization::getLocalizedURL(null, trans('routes.account-edit'), ["id" => Auth::user()->id])
But it seems like you should actually use the route name instead, meaning 'account-edit' in this case.
I am using laravel 4 and I have created a file inside app/config as follows : The file name is aws.php
<?php
return [
'key' => 'xyz',
];
Now, from my controller I tried to access the key as follows :
$key = Config::get('aws.key');
but it returns null. How can I solve this problem ? I have googled it but have not found the solution.
You can access "key" by Config::get('aws.key');
but need to run this command: php artisan config:clear
try
$key = \Config::get('aws.key');
Config is not in the same namespace as class that call this facade, so You want to go to global namespace to search Config class