“Laravel Json Search” Kode Jawaban

Laravel Json Search

public function search()
    {
        $search   = request()->input('search');
        $products = DB::table('products')
            ->whereRaw("LOWER(JSON_EXTRACT(name, \"$.".app()->getLocale()."\")) LIKE ?", ["%".strtolower($search)."%"])
            ->whereNull('deleted_at')
            ->select(['id', 'name', 'slug',])
            ->orderBy('id', 'desc')
            ->limit(15)->get()->transform(function ($product) {
                $data = collect($product)->toArray();

                return new ProductSearchViewModel($data);
            });

        return JsonReturnViewModel::toJsonBeautify($products);
    }
Shadow

Laravel Query Json

$users = DB::table('users')
                ->whereJsonContains('options->languages', ['en', 'de'])
                ->get();
Clean Crab

Laravel json di mana kueri

$users = DB::table('users')
                ->where('options->language', 'en')
                ->get();

$users = DB::table('users')
                ->where('preferences->dining->meal', 'salad')
                ->get();

Jawaban yang mirip dengan “Laravel Json Search”

Pertanyaan yang mirip dengan “Laravel Json Search”

Lebih banyak jawaban terkait untuk “Laravel Json Search” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya