So I found MySQL COALESCE()
$products = Product_Lang::select(\DB::raw('products_lang.*'))
->join('products', 'products_lang.product_id', '=', 'products.id')
->join('category_product', 'products.id', '=', 'category_product.product_id')
->where('language_code', App::getLocale())
->where('display', 1)
->where('category_id', $category->id)
->selectRaw('CONCAT(name, " ", model) AS product_name, products.id')
->selectRaw('COALESCE(discount_price, price) AS product_price')
->orderBy($sortby, $order)
->paginate(50);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community