PHP code example of jcshoww / query-collection

1. Go to this page and download the library: Download jcshoww/query-collection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jcshoww / query-collection example snippets

bash

...
use Jcshoww\QueryCollection\QueryCollection;

class TestQueryCollection extends QueryCollection
{
    /**
     * {@inheritDoc}
     */
    public function __construct(array $fields = [])
    {
        $this->push(new CustomFilter('status', $fields['status']));
    }
}
bash
...
use Jcshoww\QueryCollection\Builder\Builder;
use Jcshoww\QueryCollection\Query\Query;

class Join extends Query
{
    /**
     * {@inheritDoc}
     */
    protected $type = 'Join';

    /**
     * table name
     * 
     * @var string
     */
    protected $table;

    /**
     * owner column to join
     * 
     * @var string
     */
    protected $ownerColumn;
    
    /**
     * foreign column to join
     * 
     * @var string
     */
    protected $foreignColumn;

    /**
     * @param string $table
     * @param string $ownerColumn
     * @param string $foreignColumn
     */
    public function __construct(string $table, string $ownerColumn, string $foreignColumn)
    {
        $this->table = $table;
        $this->ownerColumn = $ownerColumn;
        $this->foreignColumn = $foreignColumn;
    }

    /**
     * @param LaravelBuilder $builder
     * 
     * @return Query
     */
    public function apply(Builder $builder): Query
    {
        $builder->join($this->table, $this->ownerColumn, Where::EQUAL, $this->foreignColumn);
        return $builder;
    }
}