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'
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'
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 .
Solution:
$result = DB::table('cliente')
->select(DB::raw("CONCAT( TRIM(SUBSTRING( NombreCliente,1,1) ), TRIM(SUBSTRING( NombreCliente, locate( ' ',NombreCliente), 2) ) ) AS INICIALES"))
->get();