<?php
/**
 * Created by PhpStorm.
 * User: 思维定制
 * Date: 2018/7/19
 * Time: 18:39
 */

namespace App\Repositories\Messages\Criteria;

use App\Repositories\Base\Criteria;
use App\Repositories\Contracts\RepositoryInterface as Repository;
class TagWhere extends Criteria {

    private $search = [];

    /**
     * MultiWhere constructor.
     * @param array $search
     *
     */
    public function __construct(array $search)
    {
        $this->search = $search;
    }

    /**
     * @param $model
     * @param RepositoryInterface $repository
     * @return mixed
     */
    public function apply($model, Repository $repository)
    {
        if(isset($this->search['keyword']) && ! empty($this->search['keyword'])) {
            $keywords = '%' . $this->search['keyword'] . '%';
            $model = $model->where(function ($query) use ($keywords) {
                $query->where('id'  , 'like', $keywords)
                    ->orwhere('name', 'like', $keywords);
            });
        }
        return $model;
    }
}