Thanks so much for your answer @matapatos .
I tried following your guide. I’m stuck on your step 3, because I’m not able to move the functions from the helpers.php to Composers.
I’m getting the error “Class “Roots\Sage\Container” not found”. After some research, I understood that the sage() function isn’t used anymore in Sage 10.
If I understand correctly, I don’t need the sage() function anymore. So I removed it, and I created a Composer for each of the other functions of my helpers.php file. And then, how do I register these Composers? Do I need to create a app/providers/AppServiceProvider.php file? Or are Composers registered automatically?
Here’s my helpers.php code :
<?php
namespace App;
use Roots\Sage\Container;
/**
* Get the sage container.
*
* @param string $abstract
* @param array $parameters
* @param Container $container
* @return Container|mixed
*/
function sage($abstract = null, $parameters = [], Container $container = null)
{
$container = $container ?: Container::getInstance();
if (!$abstract) {
return $container;
}
return $container->bound($abstract)
? $container->makeWith($abstract, $parameters)
: $container->makeWith("sage.{$abstract}", $parameters);
}
/**
* Get / set the specified configuration value.
*
* If an array is passed as the key, we will assume you want to set an array of values.
*
* @param array|string $key
* @param mixed $default
* @return mixed|\Roots\Sage\Config
* @copyright Taylor Otwell
* @link https://github.com/laravel/framework/blob/c0970285192483ab40525a34a71f346f4e43e0e9/src/Illuminate/Foundation/helpers.php#L254-L265
*/
function config($key = null, $default = null)
{
if (is_null($key)) {
return sage('config');
}
if (is_array($key)) {
return sage('config')->set($key);
}
return sage('config')->get($key, $default);
}
/**
* Retrieve path to a compiled blade view
* @param $file
* @param array $data
* @return string
*/
function template_path($file, $data = [])
{
return sage('blade')->compiledPath($file, $data);
}
/**
* @param $asset
* @return string
*/
function asset_path($asset)
{
return sage('assets')->getUri($asset);
}
Here’s an example of one of the Composers I created, for example the one for the config() function :
<?php
namespace App\View\Composers;
use Roots\Acorn\View\Composer;
class ConfigComposer extends Composer
{
protected static $views = [
'*', // Apply to all views; you can specify particular views if needed
];
public function with()
{
return [
'config' => function ($key = null, $default = null) {
return $this->container->get('config')->get($key, $default);
},
];
}
}
You can also find a screenshot of my errors as an attachment. Thanks in advance for your help everyone!