0

Work in the native query but when I turn into laravel code there is some error

I confused because my CONCAT is considered as column

$query = DB::table('bonus_produksi')
            ->join('bonus_areas', 'bonus_produksi.area', '=', 'bonus_areas.id')
            ->select('bonus_produksi.area',
                     'CONCAT(\'Rp.\',frupiah(bonus_produksi.besaran)',
                     'bonus_areas.nama_area')->get();

Unknown column 'CONCAT('Rp.',frupiah(bonus_produksi.besaran),',00')'

2

2 Answers 2

3

Inform the query builder you are using a RAW statement.

$query = DB::table('bonus_produksi')
            ->join('bonus_areas', 'bonus_produksi.area', '=', 'bonus_areas.id')
            ->select('bonus_produksi.area',
                     DB::raw("CONCAT(\'Rp.\',frupiah(bonus_produksi.besaran) as column_name"),
                     'bonus_areas.nama_area')->get();

Be sure to also include this at the top:

use DB;
Sign up to request clarification or add additional context in comments.

Comments

0

Try the below answer

$query = DB::table('bonus_produksi')
        ->join('bonus_areas', 'bonus_produksi.area', '=', 'bonus_areas.id')
        ->selectRaw("bonus_produksi.area,
                 CONCAT('Rp.',frupiah(bonus_produksi.besaran),
                 bonus_areas.nama_area")->get();

2 Comments

i try your answer but i get {"draw":1,"recordsTotal":2,"recordsFiltered":0,"data":[],"error":"Exception Message:\n\nUndefined property: stdClass::$id"}
you have to add id in your selectRaw string. dont forget to add a comma seperator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.