0

I need to pass both input and collections, that this controller produce, to the previous template. I try to use:

return redirect()->back->withInput()->with('userdata',$userdata);

but get undefined variable when access $userdata in template. This is controller:

public function inquireUpdateProcess(){
    $input = request()->all();
    $userdata = AuthorityKind::where('authority', $input['authority'])->first(); 
    return redirect()->back->withInput()->with('userdata',$userdata);
}

And this is template of view:

<label for="text-authority-change">name of authority:</label>
<input type="text" name="authority_name_change" class="form-control"
   value="{{$userdata->authority_name}}" />

I use the following instead then it works. But the outcome is couldn't pass the input data and collection in the same time, I know there must be a way to use return redirect()->back()... and get both previous input and the collection in template.

$userdata = AuthorityKind::where('authority', $input['authority'])->first();
$binding = [
    'title' => 'Authority management',
    'userdata' => $userdata,
];
return view('authority.authView', $binding);
Don't Panic
  • 13,965
  • 5
  • 32
  • 51
Josh Chang
  • 45
  • 2
  • 11
  • 1
    Did you tried to select the data directly from the database, to check if the data exists? – wbail Apr 27 '20 at 12:11
  • Yes, the data exists. Otherwise **return view('authority.authView', $binding);** should get nothing and show **undefined variable** , too. But it worked for **return view('authority.authView', $binding);** – Josh Chang Apr 27 '20 at 13:17

1 Answers1

0

I found out the data put into with() can only get it by session in template of blade like this :

<input type="text" id="text-authority-change" name="authority_name_change" class="form-control"
  value="{{session()->get('userdata')['authority_name']}}"
  />

Even the collections of Eloquent are the the same way to access.

Josh Chang
  • 45
  • 2
  • 11