title: Keeping modal dialog open after validation error laravel
body: <p>So basically I have a blade.php, controller page and a form request page(validation). I'm trying to keep my modal dialog open if there is an error but I just cant figure  it out, what part of code am I missing out on or needs to be changed? </p>
  
  <p>blade.php</p>
  
  <pre><code>&lt;div id="register" class="modal fade" role="dialog"&gt;
  ...
  
  &lt;script type="text/javascript"&gt;
  if ({{ Input::old('autoOpenModal', 'false') }}) {
      //JavaScript code that open up your modal.
      $('#register').modal('show');
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller.php</p>
  
  <pre><code>class ManageAccountsController extends Controller
  {
      public $userRepository;
  
      public function __construct(UserRepository $userRepository)
      {
          $this-&gt;userRepository = $userRepository;
      }
  
      public function index() 
      {
          $users = User::orderBy('name')-&gt;get();
          $roles = Role::all();
  
          return view('manage_accounts', compact('users', 'roles'));
      }
  
      public function register(StoreNewUserRequest $request)
      {
          // process the form here
          $this-&gt;userRepository-&gt;upsert($request);
          Session::flash('flash_message', 'User successfully added!');
  
          //$input = Input::except('password', 'password_confirm');
          //$input['autoOpenModal'] = 'true'; //Add the auto open indicator flag as an input.
  
          return redirect()-&gt;back();
      }
  }
  
  class UserRepository {
  
      public function upsert($data)
      {
  
              // Now we can separate this upsert function here
          $user = new User;
          $user-&gt;name     = $data['name'];
          $user-&gt;email    = $data['email'];
          $user-&gt;password = Hash::make($data['password']);
          $user-&gt;mobile   = $data['mobile'];
          $user-&gt;role_id  = $data['role_id'];
  
              // save our user
          $user-&gt;save();
  
          return $user;
      }
  }
  </code></pre>
  
  <p>request.php</p>
  
  <pre><code>class StoreNewUserRequest extends Request
  {
      /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
      public function authorize()
      {
          return true;
      }
  
      /**
       * Get the validation rules that apply to the request.
       *
       * @return array
       */
      public function rules()
      {
          // create the validation rules ------------------------
  
          return [
          'name'             =&gt; 'required',                        // just a normal required validation
          'email'            =&gt; 'required|email|unique:users',     // required and must be unique in the user table
          'password'         =&gt; 'required|min:8|alpha_num',
          'password_confirm' =&gt; 'required|same:password',           // required and has to match the password field
          'mobile'           =&gt; 'required', 
          'role_id'          =&gt; 'required'
          ];
      }
  }
  </code></pre>