Mam aplikację opartą na pakiecie laravel 5. W pakiecie jest to moja struktura:
Packages
-vendor
-xxx
-public
-src
-config
-config.php
-Vendor
-Xxx
-Controllers
-Models
-Repositories
XxxServiceProvider.php
-views
routes.php
** Powyższe jest moją strukturą pakietu: xxx to nazwa pakietu.
W tym config / config.php mam konfiguracje, których używam w tym pakiecie.
Jak mogę uzyskać dostęp do tego pliku konfiguracyjnego, aby użyć zawartych w nim wartości?
Dodałem następujący kod w XxxServiceProvider.php
$this->publishes([ __DIR__."/xxx/src/config/config.php"=>config_path("xxx/config.php"),
]);
i php artisan vendor: opublikuj, dał następujący błąd: Czy można „znaleźć ścieżkę:
Czy ktoś może mi z tym pomóc?
Odpowiedzi:
1 dla odpowiedzi № 1Jeśli struktura twojego pakietu jest podobna do poniższej, możesz załadować plik konfiguracyjny swojego pakietu w taki sposób. Spróbuj dostosować go do własnej struktury.
/xxx
|_ /src
|_ /Config
- xxx.php
- XxxServiceProvider.php
Dodać do XxxServiceProvider.php
public function boot() {
// Allow your user to publish the config
$this->publishes([
__DIR__."/Config/xxx.php" => config_path("xxx.php"),
], "config");
}
public function register() {
// Load the config file and merge it with the user"s (should it get published)
$this->mergeConfigFrom( __DIR__."/Config/xxx.php", "xxx");
}