“Laravel -Beziehungssuche” Code-Antworten

Laravel -Suchdatenbeziehung

$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

Laravel -Beziehungssuche

//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

Ähnliche Antworten wie “Laravel -Beziehungssuche”

Fragen ähnlich wie “Laravel -Beziehungssuche”

Weitere verwandte Antworten zu “Laravel -Beziehungssuche” auf PHP

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen