Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel search data relationship

$data = Subcategory::with(["category"])
                            ->where('name','like', '%'.$this->searchData.'%')
                            ->orWhereHas('category', function($query){$query->where('name', 'like', '%'.$this->searchData.'%');})
                            ->orderBy($this->orderByData, $this->orderByAsc ? 'asc' : 'desc')
                            ->paginate($this->showData);
Comment

laravel relationship search

//Search
public function autocomplete(Request $request)
    {
        $name = $request->get('name');

        $filter = DB::table('filters')
            ->join('filter_values', 'filters.id', '=', 'filter_values.filter_id')
            ->whereNull(['filters.deleted_at', 'filter_values.deleted_at'])
            ->select('filters.name as filter_name',
                'filter_values.name as filter_value_name',
                'filter_values.id as id',
                'filter_values.sort_filter as sort_filter')
            ->limit(15)->orderBy('sort_filter', 'asc')
            ->where('filter_values.name', 'like', '%' . $name . '%')
            ->get()->map(function ($item) {
                $item = (array)$item;
                return [
                    'id' => $item['id'],
                    'name' => AdminService::trans($item['filter_name'], null, true) . ' > ' . AdminService::trans($item['filter_value_name'], null, true),
                ];
            });

        return response()->json($filter);

    }

//Trans
public static function trans($array, $locale = null, $json = false)
    {
        if ($json === true) {
            $array = (array)json_decode($array);
        }

        if (!$locale) {
            $locale = app()->getLocale();
        }
        return $array[$locale];
    }
Comment

PREVIOUS NEXT
Code Example
Php :: add brackets to string php 
Php :: laravel trans with parameters 
Php :: create curl api request php with para 
Php :: Composer detected issues 
Php :: woocommerce product hooks 
Php :: luhn algorithm 
Php :: php call constant in class 
Php :: How to add custom button in wordpress admin section 
Php :: minishlink/web-push v5.2.5 requires ext-gmp * 
Php :: laravel search multiple tables 
Php :: get the current datetime in php when button is clicked 
Php :: ?? Null Coalescing Operator PHP 
Php :: php webpage to string 
Php :: laravel blade fontawesome 
Php :: Redirect to a specific html element - Laravel 
Php :: laravel with and where 
Php :: send mail using php mail function on localhost using xampp server 
Php :: how simple get ip address json 
Php :: violation: 1071 Specified key was too long; max key length is 1000 bytes 
Php :: laravel factory in custom namespace 
Php :: laravel use controller function in another controller 
Php :: call to a member function get_results() on null 
Php :: call api php 
Php :: laravel collection collapse 
Php :: laravel date diff 
Php :: smarty switch case 
Php :: woocommerce update_status 
Php :: saving an image from pc to php 
Php :: executar comando linux php 
Php :: laravel db raw count where 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =