Support the ongoing development of Laravel.io →
posted 8 years ago
Database
Last updated 2 years ago.
0

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);
Last updated 8 years ago.
0

If you are on MySQL, check CASE WHEN

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ewing1990 ewing1990 Joined 3 Feb 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.