DEV Community

JohnDivam
JohnDivam

Posted on • Edited on

Change Values in File in Laravel?

In your get function

 $mylist = config('mylist'); /config/mylist.php
  return view('...',compact('mylist'));
Enter fullscreen mode Exit fullscreen mode

In your post function

foreach ($request->except("_token") as $key => $value) {
    Config::set('mylist.' . $key, $value);
}

$text = '<?php return ' . var_export(config('mylist'), true) . ';';
file_put_contents(config_path('mylist.php'), $text);
Enter fullscreen mode Exit fullscreen mode

In blade

<form action=" " method="post">
    @csrf

    @foreach ($mylist as $key => $value)
        <div class="form-group">
            <textarea name="{{$key}}" class="form-control" rows="4">{{$value}}</textarea>
        </div>
    @endforeach

    <div class="form-group">
        <button type="submit" class="btn btn-success"> {{  __('Save') }} </button>
    </div>
</form>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)