Understanding Configuration Settings in Ravel 5.3

Asked 2 years ago, Updated 2 years ago, 83 views

Thank you for your continuous support.

I am studying Ravel using Ravel Framework version 5.3.

I wanted to put the constants and arrays used in each place in one place, so I checked various things and took the following steps, but I couldn't read the settings.

Create a new file below
/config/const.php

The contents are simply as follows:

<?php
return [
  "hoge" = > "fuga",
];

I took it out on the controller's side as follows, but

$value=Config::get('const.hoge');
echo$value;

The error appears as follows:

Class'App\Http\Controllers\xxxx\Config' not found

So,

use Config;

When I added , the error disappeared, but the important configuration is not echoed.
(White; $value was null when checked with is_null)

Where config/app.php is

'Config'=> Illuminate\Support\Facades\Config::class,

I thought the location might be strange, but I don't really want to add it to the base file army, and everywhere I looked it up, it said, "Additional configuration is possible under config, so I'd like to do so if I can within /config/const.php."

in /config/const.php
<?php
return array(
  'hoge' = > 'fuga'
);

It's no use trying to write . On the controller's side,

$value=Config:get('const.hoge');
$value=Config:get('const');

I tried it like this, but it didn't work.

How can I load it?

laravel-5

2022-09-30 16:44

1 Answers

Laravel Configuration also uses helper functions.(I just read the document, so I didn't check it.)

$value=config('const.hoge');

Also, if you are using a facade in Ravel 5.3, it is not useConfig; but

use Illuminate\Support\Facades\Config;

It's good to say that


2022-09-30 16:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.