php - keep old value in form laravel 5.3 -
i have form have 2 buttons 1 save , add another , 2nd save , exit have field list in form want if user click on save , add list should same saved last time.in db have list_id field list here
create method
public function create() { $lists = db::table('lists')->select('id', 'name')->get(); $page_data = [ 'title' => trans('mumara.subscribers.add_new_sub.title'), 'action' => 'add' ]; $list_id = isset($_get['list_id']) ? $_get['list_id'] : null; return view('subscriber.create')->with(compact('page_data', 'lists', 'list_id')); }
here id list field
<div class="form-group"> <label class="control-label col-md-3">add list <span class="required"> * </span> </label> <div class="col-md-8"> <select class="form-control select2" name="list_id" id="list-id" {{ ($page_data['action'] == 'edit') ? 'disabled' : '' }} > <option value="0">choose list</option> @foreach($lists $list) <option value="{{ $list->id }}" {{ (isset($subscriber->list_id) && ($list->id == $subscriber->list_id)) || (!empty($list_id) && $list->id == $list_id) ? 'selected' : '' }}> {{ $list->name }}</option> @endforeach </select> </div> </div>
buttons as
<div class="col-md-offset-3"> <button type="submit" name="save_add" class="btn green" value="save_add">save & add another</button> <button type="submit" name="save_add" class="btn green" value="save_exit">save & exit</button> </div>
now want if user clicks on save , add button list should same last time saved please fix know little should pas list id create dont know how can do
i assume you're using resource
route create
function displaying create from. , store
function storing database. example showing create form use :
public function create() { // create view can change yours return view('users.form'); }
and when you're trying old data return data :
public function store(request $request) { // save data $user = new user; $user->name = $request->input('name'); $user->email = $request->input('email'); $user->save(); // return old data return view('users.form',$user); }
Comments
Post a Comment