<?php

namespace Mnv\Modules;

/**
 * Class Search
 * @package Mnv\Modules
 */
class Search
{
    public $success;
    public $errors;

    public $products = [];

    public function products($query)
    {
        if (!empty($query)) {
            connect()->grouped(function($q) use ($query) {
                $q->like('title', "%" . $query . "%")->orLike('content', "%" . $query . "%")->orLike('keywords',"%" . $query . "%");
            });
        }

        $this->products = connect('products')->select('title, url')->getAll('array');
    }

}