In any config file If I use URL class I get the error 'Class URL not found'; if I use the function "asset", when I update composer.json I get this error: Catchable fatal error: Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given,
Outside of config files both work fine
return [
'photos_url' => URL::asset('xxx'),
];
or
return [
'photos_url' => asset('xxx'),
];
Test
echo config('site.photos_url'); // or echo Config::get('site.photos_url');
Configs are loaded really early and probably not meant to use anything from the framework except Dotenv
return [
'photos_url' => URL::asset('xxx'),
];
Instead you can use:
return [
'photos_url' => env('APP_URL').'/rest_of_path.ext',
];
Source: Laravel Issue #7671
You shouldn't use dynamic code in your config. As a solution you can use ConfigServiceProvider
to add any specific cases:
public function register()
{
config([
'photos_url' => assets('xxx'),
'services.facebook.redirect' => url('auth/callback/facebook'),
]);
}
Source: https://github.com/laravel/framework/issues/7671
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With