SQL query in Laravel

1

How can I pass the following query in Laravel 5.4

SELECT CONCAT( 
  TRIM(SUBSTRING(NombreCliente,1,1)),  
  TRIM(SUBSTRING(NombreCliente, locate( ' ',NombreCliente), 2) ) 
)INICIALES FROM 'cliente'
    
asked by arch 14.06.2018 в 22:49
source

2 answers

1

Try simply putting your custom selection within select of Query Builder :

  $result = DB::table('cliente')
            ->selectRaw("CONCAT( TRIM(SUBSTRING( NombreCliente,1,1) ), TRIM(SUBSTRING( NombreCliente, locate( ' ',NombreCliente), 2) ) ) INICIALES")
            ->get();

To learn more about Query Builder here official documentation link .

    
answered by 14.06.2018 в 23:09
0

Solution:

$result = DB::table('cliente')
      ->select(DB::raw("CONCAT( TRIM(SUBSTRING( NombreCliente,1,1) ), TRIM(SUBSTRING( NombreCliente, locate( ' ',NombreCliente), 2) ) ) AS INICIALES"))
      ->get();
    
answered by 15.06.2018 в 00:53