Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined method Illuminate\Database\Query\Builder

I am new to laravel 4 and keep getting the same error trying to learn about some methods in DB class.

Call to undefined method Illuminate\Database\Query\Builder

I get same erros trying to use "->or_where", "->order_by".

another problem is parsing the dynamic methods:

->where_name("test") 

turns into

`users` where `_name` = test)

but if i try to do

->wherename("test")

then everything is fine.

like image 681
Brightside Avatar asked Dec 09 '22 09:12

Brightside


1 Answers

You're using an incorrect syntax for orWhere and orderBy.

This is the correct syntax for orWhere:

DB::table('users')
    ->where('name', '=', 'John')
    ->orWhere(function($query)
    {
         $query->where('votes', '>', 100)
               ->where('title', '<>', 'Admin');
    })
    ->get();

And this for orderBy:

$users = DB::table('users')
                 ->orderBy('name', 'desc')
                 ->get();

Query Builder - Advanced Wheres - Laravel

like image 135
Mariano Córdoba Avatar answered Dec 11 '22 07:12

Mariano Córdoba