Case When Like in Eloquent in Laravel

Solution:

Try with "(CASE WHEN akun LIKE '%51%' THEN 51 ELSE 0 END )" Notice the double quote to contain the whereRaw statement.

And to send dynamic data you can try "(CASE WHEN akun LIKE '%".data."%' THEN 51 ELSE 0 END )"

So your query should look like this:

$realisasi=Realisasi::whereRaw("(CASE WHEN akun LIKE '%".$data."%' THEN 51 ELSE 0 END )')
                    ->whereYear('tanggal','2020')
                    ->where('kdsatker','412772')
                    ->groupby('akun')
                     ->get();

MySQL requires the like pattern to be inside single quotes. For more reference: https://dev.mysql.com/doc/refman/8.0/en/pattern-matching.html