更新本地化数组值

Update Localization array value

我正在更新 lang 文件夹下文件的值。所有文件都有一个数组,我想从用户那里更新该数组的值。

例如,

en/messages.php 个文件有类似

的数组
<?php 
    return [
       'hello' => 'hi'
    ];

现在我将这些对发送给用户。用户可以更改该标签的唯一值。

我所做的是

public function update(Request $request, $lang, $file)
{
   $r = $request->input('lang');
   Storage::put('lang/' . $lang . '/' . $file.'.php', $r);
   return redirect()->back();
}

但我只得到该数组的值。我想要一个文件中的输出,如:

期望的输出:

<?php
   return [
      'hello' => 'helo'
   ];

我是这样完成的,

    public function update(Request $request, $lang, $file)
    {
            $r = $request->input('lang');
            $textContent = " <?php  
                return [ ";
            foreach ($r as $label => $value) {
                $textContent .= '"' . $label . '" => "' . $value . '",';
            }
            $textContent .= '];';
            Storage::put('lang/' . $lang . '/' . $file . '.php', $textContent);
            return back();
        }