Eloquent: request field length in Laravel

I want to do something like this in Laravel (valid sqlite query):

select * from 'tbUsers' where  length(name)>50;

I tried

User::with('Permissons')->where('LENGTH(name)','>','50')->get();

But it does not seem to work ........

note : other queries work without problems:

User::with('Permissons')->where('active','=','1')->get();
+4
source share
2 answers

try it whereRaw( string $sql, array $bindings = array(), string $boolean = 'and')

User::with('Permissons')->whereRaw('LENGTH(name) > 50')->get();
+10
source

Use whereRaw:

User::with('Permissons')->whereRaw('LENGTH(name) > ?', [50])->get();
+3
source

All Articles