“Pencarian Hubungan Laravel” Kode Jawaban

Hubungan data pencarian Laravel

$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);
hirohito

Pencarian Hubungan Laravel

//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];
    }
Shadow

Jawaban yang mirip dengan “Pencarian Hubungan Laravel”

Pertanyaan yang mirip dengan “Pencarian Hubungan Laravel”

Lebih banyak jawaban terkait untuk “Pencarian Hubungan Laravel” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya