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 :: random number generator in php 
Php :: laravel validate telephone number 
Php :: remove space from string php 
Php :: array_unique 
Php :: laravel check if object empty 
Php :: generate autodump laravel 
Php :: datetime difference in php 
Php :: api headers php 
Php :: page load time in php 
Php :: php is string 
Php :: display category name wordpress 
Php :: hide wordpress errors 
Php :: php get current url without filename 
Php :: determine special characters in php 
Php :: must be an instance of IlluminateHttpRequest 
Php :: get featured image url in wordpress 
Php :: magento 2 get connection 
Php :: laravel withtrashed 
Php :: php myadmin reset auto incremente 
Php :: check if number is float in php 
Php :: laravel where creation is today carbon 
Php :: codeigniter 3 insert 
Php :: format uang rupiah di php 
Php :: php copyright footer 
Php :: php sql connection string 
Php :: array empty check in php 
Php :: reload page in php 
Php :: apache htaccess read from /public 
Php :: set font sytle phpspreadsheet 
Php :: how to add properties to the request object 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =