title: How to validate unique fields while updating in make:request in laravel
body: <p>I'm developing a small application in <code>Laravel 5.5</code> where I'm creating a request with <code>updateContact</code> and having unique email validation rule, while using the same validation inside the controller I can easily make:</p>
  
  <pre><code>$contact = Contact::find($request-&gt;id);
  Validator::make($data, [
      'first_name' =&gt; 'required|max:255',
      'email' =&gt; 'required', Rule::unique('contacts')-&gt;ignore($contact-&gt;id),
      'address' =&gt; 'max:255',
      'city' =&gt; 'max:255',
      'state' =&gt; 'max:255',
      'country' =&gt; 'max:255',
  ]);
  </code></pre>
  
  <p>and can validate, by I made out request through <code>php artisan make:request UpdateContact</code> and added the following inside <code>updateContact.php</code>:</p>
  
  <p>
  
  <pre><code>namespace App\Http\Requests;
  
  use App\Contact;
  use Illuminate\Foundation\Http\FormRequest;
  use Illuminate\Validation\Rule;
  
  class UpdateContact extends FormRequest
  {
      /**
       * 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()
      {
          $contact = Contact::find($request-&gt;id);
          return [
              'first_name' =&gt; 'required|max:255',
              'email' =&gt; 'required', Rule::unique('contacts')-&gt;ignore($contact-&gt;id),
              'company_id' =&gt; 'required',
              'address' =&gt; 'max:255',
              'city' =&gt; 'max:255',
              'state' =&gt; 'max:255',
              'country' =&gt; 'max:255',
          ];
      }
  
      public function messages()
      {
          return [
              'company_id.required' =&gt; 'Company name is required'
          ];
      }
  }
  </code></pre>
  
  <p>But I don't know about the <code>$request-&gt;id</code> how can I use this?</p>