PHP code example of advancelearn / search-elequent
1. Go to this page and download the library: Download advancelearn/search-elequent 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/ */
advancelearn / search-elequent example snippets
composer
use Advancelearn\SearchElequent\Searchable;
class Order extends Model
{
use Searchable;
/**
* Scope to perform a search operation.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $searchText
* @return \Illuminate\Database\Query\Builder
*/
public function scopeSearch($query, string $searchText)
{
$searchColumns = ['order_number'];
$relationColumns = [
'address.user' => ['email'] // Nested relationship with address and user
];
return $this->search($query, $searchText, $searchColumns, $relationColumns);
}
/**
* Define the address relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function address()
{
// Define your address relationship logic here
}
}
$searchText = $request->q; // 'DE1253005'
// $searchText2 = "[email protected]";
return Order::search($searchText)->get();