Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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);
    }
 
PREVIOUS NEXT
Tagged: #laravel #json #search
ADD COMMENT
Topic
Name
2+9 =