Home > Software design >  Laravel - Query Buider - SQL fields using LPAD statement
Laravel - Query Buider - SQL fields using LPAD statement

Time:10-23

I'm cannot retry this query, in QueryBuilder:

select id, lpad(number, 12, 0), lpad(int, 2, 0) from users;

How I can, in the example not function...

DB::table('users') ->select('id', 'lpad(number, 12, 0)', 'lpad(int, 2, 0)' ->get();

CodePudding user response:

You need to use selectRaw.

DB::table('users')
    ->selectRaw('id, lpad(number, 12, 0), lpad(int, 2, 0)')
    ->get();

https://laravel.com/docs/8.x/queries#selectraw

  • Related