skip to Main Content

How am I able to return view(‘support’) with following:

->withInput()
->with('success', 'Found results');

Code

  // if validation do not fail
        if ($validated->fails() === false) {
            //session()->flashInput($request->input());
            // return
            return view('siteadmin.support.support', [
                'articles' => $articles,
                'categories' => $categories,
            ]);
        }

Following code is not working:
Code

  // if validation do not fail
        if ($validated->fails() === false) {
            //session()->flashInput($request->input());
            // return
            return view('siteadmin.support.support', [
                'articles' => $articles,
                'categories' => $categories,
            ])
            ->withInput()
            ->with('success', 'Found results');
        }

3

Answers


  1. So you can do this in multiple ways. Through sessions or through the view. Firstly if you have session messages setup you can throw a message like this

    $request->session()->flash('success','Found Results'); 
    return view('...')->withInput();
    

    Or you can pass the success message through the view like

    return view('siteadmin.support.support', compact('articles', 'categories'), [
       'success' => 'Results Found'
    ])->withInput();
    
    Login or Signup to reply.
  2. You may use the withInput method provided by the RedirectResponse instance to flash the current request’s input data to the session before redirecting the user to a new location. This is typically done if the user has encountered a validation error. Once the input has been flashed to the session, you may easily retrieve it during the next request to repopulate the form:

    return back()->withInput();

    Login or Signup to reply.
  3. Store it in a session you can use session() helper or $request->session->put()

    // validation success
    
    session([
        'categories' => $categories,
        'articles' => $articles,
    ]);
    
    return back();
    

    then you can just access the session value in blade using the session() helper.

    <div> {{ session('categories') }}</div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search