title: Laravel 5.7: Custom Validation Rule. Can't use class injected to constructor
body: <p>I made new Rule via <code>php artisan make:rule</code> to do some custom validation by performing a query.</p>
  
  <p>So inside the Rule I made a constructor and injected repository as I used to do dozens of times everywhere across the app.</p>
  
  <pre><code>class UniqueWishListNameByUser implements Rule
  {
      private $wishListRepository;
  
      public function __construct(
          WishListRepository $wishListRepository
      ) {
          $this-&gt;wishListRepository = $wishListRepository;
      }
  }
  </code></pre>
  
  <p>However in the <code>passes</code> method I can't use the injected class.</p>
  
  <pre><code>public function passes($attribute, $value)
  </code></pre>
  
  <blockquote>
    <p>Too few arguments to function
    App\Rules\UniqueWishListNameByUser::__construct(), 0 passed in
    /home/vagrant/code/ios-portal/app/Http/Requests/Frontend/WishList/CreateWishListRequest.php
    on line 31 and exactly 1 expected</p>
  </blockquote>
  
  <p>This is because when I call the rule, it expects me to inject the class by myself.</p>
  
  <pre><code>public function rules()
  {
      return [
          'name' =&gt; [
              'required',
              'string',
              new UniqueWishListNameByUser(), // &lt;--- here no args.
          ],
      ];
  }
  </code></pre>
  
  <p>Should I inject the class somewhere else or should I invoke repository class by calling <code>app()-&gt;make()</code> which I don't want to do, unless I have to.</p>
  
  <p>Am I missing something?</p>
  
  <p>edit:</p>
  
  <p>Below code works but I want to use dependency injection instead, how?</p>
  
  <pre><code>$wishlistRepository = app()-&gt;make(WishListRepository::class);
  
  $exists = $wishlistRepository
      -&gt;where('user_id', auth()-&gt;user()-&gt;id)
      -&gt;where('customer_uuid', auth()-&gt;user()-&gt;defaultCustomer-&gt;uuid)
      -&gt;where('name', $value)
      -&gt;exists();
  </code></pre>