jeudi 22 octobre 2015

Laravel 5.1 Form Validation Redirect With Input Problems

I've a problem with Laravel 5.1 Redirect With Input. I can't seem to get old values from submitted input.

I've been research for any post in stack overflow and still stuck in this problem.

This is my request controller

public function create() {
  $this->data["pageDescription"] = "Add new page.";
  $this->data["pageSubtitle"] = $this->data["pageTitle"] . " Add New";
  $this->data["formAction"] = adminRoute("page");
  return view("admin.page.form")->with("data", $this->data)->withInput(Input::old());
}

and this is my submitted controller

public function store(Request $request) {
  Input::flash();

  $validator = Validator::make($request->all(), [
    "title" => "required|max:100",
    "url_title" => "required|max:100",
    "meta_description" => "required|max:50",
    "content_title" => "required|max:100",
    "content_description_id" => "required",
    "status" => "required|in:pending,published",
    "add_more_content" => "required|in:true,false"
  ]);

  if($validator->fails()) {
    return redirect()->back()
              ->with("data", $this->data)
              ->withErrors($validator)
              ->withInput();
  } else {
    return redirect()->back()->withInput();
  }
}

It's kinda weird because when I dump Session::all() before I redirect()->back() the _old_input is exists

enter image description here

But when I dump Session::all() on my function create() the _old_input is empty.

enter image description here

Even when I skip the validation, and use

redirect()->back()->withInput();

I still got the same problem, the old values input empty

This is my form view

enter image description here

Anybody know what I am doing it wrong?

Thank youu



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire