Tengo esta consulta que me funciona bien
SELECT * FROM IGNom_Trabajador WHERE REPLACE(CODIGO, '.', '') = 12345678
Pero cuando trato de hacerlo con Laravel me da error, he tratado de la siguiente forma
DB::connection('sqlsrv')->select(DB::raw('REPLACE("CODIGO", ".", "")'))->where("CODIGO", "=", 12345678);
Employee::whereRaw('IGNom_Trabajador.*, REPLACE("CODIGO", ".", "")', '=', '12345678')->first();
Ninguna de estas me funciona, me retornan un objecto con la información de mi conexion a la base de datos y demas pero sin la información.
¿Como puedo traducir correctamente esta sentencia para usarla con Laravel?
Lo que me devuelve la consulta
C:\wamp\www\SPI\intranet\app\Http\Controllers\UserController.php:84:
object(Illuminate\Database\Eloquent\Builder)[344]
protected 'query' =>
object(Illuminate\Database\Query\Builder)[343]
public 'connection' =>
object(Illuminate\Database\SqlServerConnection)[342]
protected 'pdo' =>
object(Closure)[341]
...
protected 'readPdo' => null
protected 'database' => string 'NOMDB' (length=5)
protected 'tablePrefix' => string '' (length=0)
protected 'config' =>
array (size=8)
...
protected 'reconnector' =>
object(Closure)[354]
...
protected 'queryGrammar' =>
object(Illuminate\Database\Query\Grammars\SqlServerGrammar)[338]
...
protected 'schemaGrammar' => null
protected 'postProcessor' =>
object(Illuminate\Database\Query\Processors\SqlServerProcessor)[336]
...
protected 'events' =>
object(Illuminate\Events\Dispatcher)[26]
...
protected 'fetchMode' => int 5
protected 'transactions' => int 0
protected 'recordsModified' => boolean false
protected 'queryLog' =>
array (size=0)
...
protected 'loggingQueries' => boolean false
protected 'pretending' => boolean false
protected 'doctrineConnection' => null
public 'grammar' =>
object(Illuminate\Database\Query\Grammars\SqlServerGrammar)[338]
protected 'operators' =>
array (size=18)
...
protected 'selectComponents' =>
array (size=12)
...
protected 'tablePrefix' => string '' (length=0)
public 'processor' =>
object(Illuminate\Database\Query\Processors\SqlServerProcessor)[336]
public 'bindings' =>
array (size=7)
'select' =>
array (size=0)
...
'from' =>
array (size=0)
...
'join' =>
array (size=0)
...
'where' =>
array (size=1)
...
'having' =>
array (size=0)
...
'order' =>
array (size=0)
...
'union' =>
array (size=0)
...
public 'aggregate' => null
public 'columns' =>
array (size=1)
0 =>
object(Illuminate\Database\Query\Expression)[346]
...
public 'distinct' => boolean false
public 'from' => string 'IGNom_Trabajador' (length=16)
public 'joins' => null
public 'wheres' =>
array (size=1)
0 =>
array (size=5)
...
public 'groups' => null
public 'havings' => null
public 'orders' => null
public 'limit' => null
public 'offset' => null
public 'unions' => null
public 'unionLimit' => null
public 'unionOffset' => null
public 'unionOrders' => null
public 'lock' => null
public 'operators' =>
array (size=29)
0 => string '=' (length=1)
1 => string '<' (length=1)
2 => string '>' (length=1)
3 => string '<=' (length=2)
4 => string '>=' (length=2)
5 => string '<>' (length=2)
6 => string '!=' (length=2)
7 => string '<=>' (length=3)
8 => string 'like' (length=4)
9 => string 'like binary' (length=11)
10 => string 'not like' (length=8)
11 => string 'ilike' (length=5)
12 => string '&' (length=1)
13 => string '|' (length=1)
14 => string '^' (length=1)
15 => string '<<' (length=2)
16 => string '>>' (length=2)
17 => string 'rlike' (length=5)
18 => string 'regexp' (length=6)
19 => string 'not regexp' (length=10)
20 => string '~' (length=1)
21 => string '~*' (length=2)
22 => string '!~' (length=2)
23 => string '!~*' (length=3)
24 => string 'similar to' (length=10)
25 => string 'not similar to' (length=14)
26 => string 'not ilike' (length=9)
27 => string '~~*' (length=3)
28 => string '!~~*' (length=4)
public 'useWritePdo' => boolean false
protected 'model' =>
object(App\Employee)[340]
protected 'connection' => string 'sqlsrv' (length=6)
protected 'table' => string 'IGNom_Trabajador' (length=16)
protected 'primaryKey' => string 'Consecutivo_Trabajador' (length=22)
protected 'keyType' => string 'int' (length=3)
public 'incrementing' => boolean true
protected 'with' =>
array (size=0)
empty
protected 'withCount' =>
array (size=0)
empty
protected 'perPage' => int 15
public 'exists' => boolean false
public 'wasRecentlyCreated' => boolean false
protected 'attributes' =>
array (size=0)
empty
protected 'original' =>
array (size=0)
empty
protected 'changes' =>
array (size=0)
empty
protected 'casts' =>
array (size=0)
empty
protected 'dates' =>
array (size=0)
empty
protected 'dateFormat' => null
protected 'appends' =>
array (size=0)
empty
protected 'dispatchesEvents' =>
array (size=0)
empty
protected 'observables' =>
array (size=0)
empty
protected 'relations' =>
array (size=0)
empty
protected 'touches' =>
array (size=0)
empty
public 'timestamps' => boolean true
protected 'hidden' =>
array (size=0)
empty
protected 'visible' =>
array (size=0)
empty
protected 'fillable' =>
array (size=0)
empty
protected 'guarded' =>
array (size=1)
0 => string '*' (length=1)
protected 'eagerLoad' =>
array (size=0)
empty
protected 'localMacros' =>
array (size=0)
empty
protected 'onDelete' => null
protected 'passthru' =>
array (size=12)
0 => string 'insert' (length=6)
1 => string 'insertGetId' (length=11)
2 => string 'getBindings' (length=11)
3 => string 'toSql' (length=5)
4 => string 'exists' (length=6)
5 => string 'doesntExist' (length=11)
6 => string 'count' (length=5)
7 => string 'min' (length=3)
8 => string 'max' (length=3)
9 => string 'avg' (length=3)
10 => string 'sum' (length=3)
11 => string 'getConnection' (length=13)
protected 'scopes' =>
array (size=0)
empty
protected 'removedScopes' =>
array (size=0)
empty