How can I get inpu...">

Laravel gets old input with dotted notation

My input name is as follows: <input name="settings[custom_plan.breakpoint1]"/>

How can I get input oldfor it? Because dot notation works for an input array, but not in the actual name. Thus, it old('settings[custom_plan.breakpoint1]')does not work, and none of them is old('settings.custom_plan\.breakpoint1')(escaping a point works in check notation).

How to get old value for input?

Thank!

+4
source share
1 answer

You can use old()to get the whole array, and then manually extract the value:

{{ old('settings')['custom_plan.breakpoint1'] }}

Unfortunately, there is no way to use dotted notation for this. old()helper uses the method Illuminate\Support\Arr@get, and there is a key piece of code:

foreach (explode('.', $key) as $segment) {
    if (static::accessible($array) && static::exists($array, $segment)) {
        $array = $array[$segment];
    } else {
        return value($default);
    }
}

, , , , , . .

+1

Source: https://habr.com/ru/post/1694309/


All Articles