title: Edit profile page using laravel
body: <p>Whenever a user goes to mywebsite.com/profile I want a form to pre populate the values they've entered during the signup/registration flow. <br><br>I was able to do that with my form here </p>
  
  <pre><code>&lt;h1&gt;&lt;b&gt;Your Profile&lt;/b&gt;&lt;/h1&gt;
  &lt;form method="POST" action="/profile/update"&gt;
      &lt;div class="form-group hidden"&gt;
          &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
          &lt;input type="hidden" name="_method" value="PATCH"&gt;
      &lt;/div&gt;
      &lt;div class="form-group {{ $errors-&gt;has('name') ? ' has-error' : '' }}"&gt;
          &lt;label for="email" class="control-label"&gt;&lt;b&gt;Name:&lt;/b&gt;&lt;/label&gt;
          &lt;input type="text" name="name" placeholder="Please enter your email here" class="form-control" value="{{ $user-&gt;name }}"/&gt;
  
          &lt;?php if ($errors-&gt;has('name')) :?&gt;
          &lt;span class="help-block"&gt;
              &lt;strong&gt;{{$errors-&gt;first('name')}}&lt;/strong&gt;
          &lt;/span&gt;
          &lt;?php endif;?&gt;
  
      &lt;/div&gt;
      &lt;div class="form-group {{ $errors-&gt;has('email') ? ' has-error' : '' }}"&gt;
          &lt;label for="email" class="control-label"&gt;&lt;b&gt;Email:&lt;/b&gt;&lt;/label&gt;
          &lt;input type="text" name="email" placeholder="Please enter your email here" class="form-control" value="{{ $user-&gt;email }}"/&gt;
  
          &lt;?php if ($errors-&gt;has('email')) :?&gt;
          &lt;span class="help-block"&gt;
              &lt;strong&gt;{{$errors-&gt;first('email')}}&lt;/strong&gt;
          &lt;/span&gt;
          &lt;?php endif;?&gt;
  
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;button type="submit" class="btn btn-default"&gt; Submit &lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>But now im running into the issue if the user just hits submit button without changing any fields, laravel's built in validations checks and gives me an error message of <code>The name has already been taken.</code> which is true. so im not sure how to handle this issue, but here is my controller below</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Auth;
  use App\User;
  use Illuminate\Http\Request;
  
  use App\Http\Controllers\Controller;
  
  class ProfileController extends Controller
  {
      /**
       * Update user profile &amp; make backend push to DB
       * 
      **/
  
      public function index() {
  
          /**
           * fetching the user model
           **/
          $user = Auth::user();
          //var_dump($user);
  
          /**
           * Passing the user data to profile view
           */
          return view('profile', compact('user'));
  
      }
  
      public function update(Request $request) {
          /**
           * Validate request/input 
           **/
          $this-&gt;validate($request, [
              'name' =&gt; 'required|max:255|unique:users',
              'email' =&gt; 'required|email|max:255|unique:users',
          ]);
  
          /**
           * storing the input fields name &amp; email in variable $input
           * type array
           **/
          $input = $request-&gt;only('name','email');
  
          /**
           * fetching the user model
           */
          $user = Auth::user();
  
          /**
           * Accessing the update method and passing in $input array of data
           **/
          $user-&gt;update($input);
  
          /**
           * after everything is done return them pack to /profile/ uri
           **/
          return back();
      }
  }
  </code></pre>
  
  <p>and here is my routes file.</p>
  
  <pre><code>// only authenticated users
  Route::group( ['middleware' =&gt; 'auth'], function() {
  
      Route::get('/home', 'HomeController@index');
  
      // practicing using forms for sending data to the DB &amp; populating form fields with DB data
      Route::get('profile', 'ProfileController@index');
      Route::patch('profile/{id}', 'ProfileController@update');
  
  });
  </code></pre>