I have made a config test.php
return [
'name' => 'Testname',
'street' => 'Teststraße',
'street_number' => '69',
'zip' => '42077',
'city' => 'Winterfell',
'telephone' => '0123456789',
'email' => '[email protected]'
];
created a ConfigServiceProvider:
public function register()
{
config([
'config/test.php'
]);
}
but in my test.blade.php I can access the contents only via
{{config('test.0.name')}}
There has got to be a better, easier way for this right? The data is supposed to be used in multiple blades. Yet the ".0." feels so unnecessary.
I am new to PHP and Laravel, and I am using PHP 8.1 and Laravel 9.14.
Thanks in advance!
#######################
Edit: In my case I had the problem, that my cache wasn't cleared "php artisan config:cache" thanks to @matheenulla for hinting at that!. Thats why I tried the route with the ServiceProvider. I hope this may help someone in the future!
CodePudding user response:
You don't need to create a service provider to use your config, unless you want it to be in some other location (in case you are creating a custom Laravel package), so you may delete your ConfigServiceProvider
. In fact, you're just using config wrong:
{{config('test.0.name')}}
should be:
{{config('test.name')}}