0

Trying to make a redirect with the value of specific input data once the validation fails.

  public function authorize() {
   $data = $this->all();
   return redirect()->back()->with('cat_id',$data['category_id']);
  }

public function rules()
    {
        if($this->getMethod() == 'POST') {
            return [
             'category_id' => 'required',
            ];

        } 
    }

What I want is to redirect the request back with category_id input value. Looked at documentation of laravel but couldn't find the way.

Tried : $this->input('category_id') , request()->category_id, $this->route()->parameter('category_id'), $this->get("category_id")

None of them above used to work unfortunately.Any suggestion would be highly appreciated.

  • the redirect back is going to have all the inputs already by default with how FormRequests work .... are you just trying to rename that input? also the `authorize` method is for authorizing, not sure what you are trying to do with it – lagbox Dec 02 '22 at 17:17
  • I need the value of `category_id` and send it back within `redirect()` function. As I am using extended `Request` form I am unable to use `redirect()` in my controller file. I am not stick only on `authorize()` function but inside of this anywhere would be fine. – Mahmud Abdullayev Dec 02 '22 at 17:24
  • at least if I would be able to ignore the `redirect` function which works inside of the custom validation and make it work from controller level that also would solve my issue. – Mahmud Abdullayev Dec 02 '22 at 17:54
  • `request()->session()->get('cat_id')` – itachi Dec 02 '22 at 19:03
  • I beleive you suggest the line like this: `return redirect()->back()->with('cat_id', request()->session()->get('cat_id'));` which I did know but no, doesn't work can't get value. – Mahmud Abdullayev Dec 02 '22 at 19:13

0 Answers0