title: Argument 1 passed to Illuminate\\Database\\Eloquent\\Model::__construct() must be of the type array, object given
body: <p>I want to add product to wishlist and following repository pattern to store product id and user id of the user who wants to add product to his wishlist but when i run my code i get </p>
  
  <blockquote>
    <p>Argument 1 passed to
    Illuminate\Database\Eloquent\Model::__construct() must be of the
    type array, object given, called in .... WishlistRepository.php</p>
  </blockquote>
  
  <p>This is my Code:</p>
  
  <blockquote>
    <p>WishlistController.php</p>
  </blockquote>
  
  <p>namespace App\Http\Controllers\Site;
      use App\Http\Controllers\Controller;
      use Illuminate\Http\Request;
      use App\Contracts\WishlistContract;</p>
  
  <pre><code>class WishlistController extends Controller
  {
      protected $wishlistRepository;
  
      public function __construct(WishlistContract $wishlistRepository)
      {
          $this-&gt;wishlistRepository = $wishlistRepository;
      }
  
      public function show()
      {
          $wishlist  = $this-&gt;wishlistRepository-&gt;listWishlist();
          return view('site.pages.wishlist', compact('wishlist'));
      }
  
      public function addToWishlist(Request $request)
      {
          $productID=$request-&gt;p_id;
          $userID=auth()-&gt;user()-&gt;id;
          $data=array('product_id'=&gt;$productID,'user_id'=&gt;$userID);
          $wishlist  = $this-&gt;wishlistRepository-&gt;addToWishlist($data);
      }
  }
  </code></pre>
  
  <blockquote>
    <p>WishlistContract.php</p>
  </blockquote>
  
  <pre><code>&lt;?php
  namespace App\Contracts;
  
  /**
   * Interface WishlistContract
   * @package App\Contracts
   */
  interface WishlistContract
  {
      /**
       * @param string $order
       * @param string $sort
       * @param array $columns
       * @return mixed
       */
      public function listWishlist(string $order = 'id', string $sort = 'desc', array $columns = ['*']);
  
      /**
       * @param array $params
       * @return mixed
       */
      public function addToWishlist(array $params);
  
      /**
       * @param  $id
       * @return mixed
       */
      //public function deleteFromWishlist($id);
  
      /**
       * @param array $params
       * @return bool
       */
      //public function updateWishlist(array $params);
  
      }
  
  
  ?&gt;
  </code></pre>
  
  <blockquote>
    <p>WishlistRepository.php</p>
  </blockquote>
  
  <pre><code>&lt;?php
  namespace App\Repositories;
  
  use App\Models\Wishlist;
  use App\Traits\UploadAble;
  use Illuminate\Http\UploadedFile;
  use App\Contracts\WishlistContract;
  use Illuminate\Database\QueryException;
  use Illuminate\Database\Eloquent\ModelNotFoundException;
  use Doctrine\Instantiator\Exception\InvalidArgumentException;
  
  /**
   * Class WishlistRepository
   *
   * @package \App\Repositories
   */
  class WishlistRepository extends BaseRepository implements WishlistContract
  {
      use UploadAble;
      public function __construct(Wishlist $model)
  {
      parent::__construct($model);
      $this-&gt;model = $model;
  }
  
  public function listWishlist(string $order = 'id', string $sort = 'desc', array $columns = ['*'])
  {
      return $this-&gt;all($columns, $order, $sort);
  }
  
  
      public function addToWishlist(array $params)
      {
          try {
              $collection = collect($params);
              $wishlist = new Wishlist($collection);
              $wishlist-&gt;save();
              return $wishlist;
          } catch (QueryException $exception) {
              throw new InvalidArgumentException($exception-&gt;getMessage());
          }
      }
  
      public function removefromWishlist($id)
      {
          $wishlist = $this-&gt;findAttributeById($id);
  
          $wishlist-&gt;delete();
  
          return $wishlist;
      }
  
      public function updateToWishlist(array $params)
      {
          $wishlist = $this-&gt;findWishlistById($params['id']);
  
          $collection = collect($params)-&gt;except('_token');
  
          $is_filterable = $collection-&gt;has('is_filterable') ? 1 : 0;
          $is_required = $collection-&gt;has('is_required') ? 1 : 0;
  
          $merge = $collection-&gt;merge(compact('is_filterable', 'is_required'));
  
          $wishlist-&gt;update($merge-&gt;all());
  
          return $wishlist;
      }
  
  
  
  }
  ?&gt;
  </code></pre>
  
  <blockquote>
    <p>view (script):</p>
  </blockquote>
  
  <pre><code>$('body').on('click', '.wishlist', function(e){
      e.preventDefault();
      var product_id=$(this).attr('data-wishlist');
  
       jQuery.ajax({
  
                url: "{{ url('/add-wishlist') }}",
                method: 'post',
                data: {
                   "p_id": product_id,"_token": "{{ csrf_token() }}",
                },
                success: function(result){
                  // input.val(result.status);
  
                }});  
  
  });
  </code></pre>