Home > database >  Laravel 8: Call to database function
Laravel 8: Call to database function

Time:04-04

I'm using a Laravel 8 for website developement, and on the next part of code, I execute a query:

$assig = DB::table('table')
->where('table.column', '=', "oneValue")
->select('anfunctionOnDatabase(2,table.columDesc)')
->get();

but it no works.

How I need call to database function on laravel?

Thanks

CodePudding user response:

Use selectRaw()

like this;

$assig = DB::table('table')
    ->where('table.column', '=', "oneValue")
    ->selectRaw('anfunctionOnDatabase(2,table.columDesc)')
    ->get();

CodePudding user response:

Use : DB::raw :

$assig = DB::table('table')
->where('table.column', '=', "oneValue")
->select(DB::raw("anfunctionOnDatabase(2,table.columDesc)"))
->get();
  • Related