title: show flash message on validation fails ( image validation ) (laravel)
body: <p>I want to show a flash message when validation fails.
  Currently the validation works but the flash message doesn't.
  I suspect my if condition is wrong</p>
  
  <pre><code>public function update_avatar(Request $request,$username){
    $this-&gt;validate($request,[
      'avatar' =&gt; 'mimes:jpeg,bmp,png|required'
    ]);
    if($request['avatar']==null){
      \Session::flash('message','Please choose a file first.');
      \Session::flash('alert-class', 'alert-warning'); 
      return redirect()-&gt;back();
    }
    if($request-&gt;hasFile('avatar')){
      $avatar = $request-&gt;file('avatar');
      $filename = time(). '.' . $avatar-&gt;getClientOriginalExtension();
      Image::make($avatar)-&gt;save('assets/src/uploads/avatars/' . $filename);
      $user = User::where('username', $username)-&gt;first();
      $user-&gt;avatar = $filename;
      $user-&gt;update();
    }
    return redirect()-&gt;route('myplace',['username' =&gt; $user-&gt;username]);
  }
  </code></pre>
  
  <p><strong>EDIT</strong>:
  form code added:</p>
  
  <pre><code>     &lt;form enctype="multipart/form-data" action="{{route('profile',['username'=&gt;$user-&gt;username])}}" method="post"&gt;
  
  
    &lt;input type="file" size="15px" name="avatar"  &gt;
  
    &lt;button type="submit" name="avatar1" class="col-md-6 col-xs-6 " value="upload" style="margin-top: 20px; width: 78px !important; " &gt;upload&lt;/button&gt;
    &lt;input type="hidden" value="{{ csrf_token() }}" name="_token"&gt;
    &lt;/form&gt;
  </code></pre>