PHP code example of workup / search-relations

1. Go to this page and download the library: Download workup/search-relations 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/ */

    

workup / search-relations example snippets


use Workup\SearchRelations\SearchesRelations;

abstract class Resource extends NovaResource
{
    use SearchesRelations;

/**
 * The relationship columns that should be searched.
 *
 * @var array
 */
public static $searchRelations = [
    'user' => ['username', 'email'],
];

/**
 * Get the searchable columns for the resource.
 *
 * @return array
 */
public static function searchableRelations(): array
{
    return [
        'user' => ['username', 'email'],
    ];
}

/**
 * The relationship columns that should be searched globally.
 *
 * @var array
 */
public static $globalSearchRelations = [
    'user' => ['email'],
];

/**
 * Get the searchable columns for the resource.
 *
 * @return array
 */
public static function globallySearchableRelations(): array
{
    return [
        'user' => ['email'],
    ];
}

/**
 * The relationship columns that should be searched globally.
 *
 * @var array
 */
public static $globalSearchRelations = [];

/**
 * Determine if relations should be searched globally.
 *
 * @var array
 */
public static $searchRelationsGlobally = false;

/**
 * The relationship columns that should be searched.
 *
 * @var array
 */
public static $searchRelations = [
    'user.country' => ['code'],
];

/**
 * Get the searchable columns for the resource.
 *
 * @return array
 */
public static function searchableRelations(): array
{
    return [
        'country' => new LocationSearch(['USA', 'UK']),
    ];
}



namespace Workup\SearchRelations\Contracts;

use Illuminate\Database\Eloquent\Builder;

interface Search
{
    /**
     * Apply search for the given relation.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @param  string  $relation
     * @param  string  $search
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function apply(Builder $query, string $relation, string $search): Builder;
}