Showing posts with label Back With Input. Show all posts
Showing posts with label Back With Input. Show all posts

Thursday, June 22, 2017

Laravel 5:Redirect back to the same page where the request comes from with input and messages

In your controller:

use Illuminate\Support\Facades\Redirect;

$error[] = "SOME ERRORS";
return Redirect::back()
    ->withErrors(compact('error'))
    ->with("reason1", "SOME REASON 1")
    ->with("reason2", "SOME REASON 2")
    ->withInput();


And in your view file:

<div>Reason1: {{ session('reason1') }}</div>

<div>Reason1: {{ session('reason2') }}</div>

Option "withInput" will fill back up input fields with previous data:

{!! Form::label('name', 'Name:') !!}