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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay