title: How can i protect profile form update by other users laravel 5.3
body: <p>This time i have Url like this 
  <strong><a href="http://Blog/user/profile/51" rel="nofollow noreferrer">http://Blog/user/profile/51</a></strong>
  and i am logged in with a user whose <strong>id = 51</strong> but if i change this id to 50 it shows the form with data of user whose id is 50 i want to stop this how i can protect help please.
  How can i check this condition before execution of othere </p>
  
  <pre><code>public function profile($id, Request $request)
      {    
  
    ***if($id == Auth::user()-&gt;id){
          Now Check get or post method
      }else{
          return ('Out');
      }***
  
  $method = $request-&gt;method();
      if ($request-&gt;isMethod('get')) {
               $user = User::findOrFail($id);
              $users = DB::table('users')-&gt;select('id', 'name')-&gt;get();
              $user_fields = DB::table('users')-&gt;where('id', $user-&gt;id)-&gt;get();
       $page_data = [
                              'title' =&gt; 'Edit User Account',
                              'action' =&gt; 'edit'
                           ];
  
              return view('user.profile')-&gt;with(compact('user', 'page_data', 'users'));
  
      }else{
      $this-&gt;validate($request, [
             'name' =&gt; 'required|max:255',
  
           ]);
  
          $user = User::findOrFail($id);
          $input = $request-&gt;all();
          $user-&gt;fill([
          'name'           =&gt; $request-&gt;input('name'),
          'password'       =&gt; $request-&gt;password ? bcrypt($request-&gt;input('password')) : $user-&gt;password,
          'time_zone'   =&gt; $request-&gt;input('time_zone'),
          'address_line_1' =&gt; $request-&gt;input('address_line_1'),
          'address_line_2' =&gt; $request-&gt;input('address_line_2'),
           ])-&gt;save();
          session()-&gt;flash('msg',trans('successfully Updated.'));
  }
  </code></pre>
  
  <p>i have idea that i can check auth user id equal to this id but dont know how to implement i am sanding url here as</p>
  
  <pre><code>&lt;form action="/user/profile/{{$user-&gt;id}}" method="POST"&gt;
  </code></pre>
  
  <p>and i am taking auth user id here as </p>
  
  <pre><code>&lt;a href="{{ route('user.profile', ['id' =&gt; Auth::user()-&gt;id ]) }}"&gt;
  </code></pre>
  
  <p>routes are as follows </p>
  
  <pre><code>Route::any('/user/profile/{id}', ['as' =&gt; 'user.profile', 'uses' =&gt; 'UserController@profile']);
  </code></pre>
  
  <p>Now how can i check before show form to user that is its related form or not
  Thanks</p>