1

All of my Laravel Model functions located in the User model refuse to work. They all return Call to undefined method Illuminate\Database\Query\Builder::foo(). If I make a function in another model, the relationships and everything works. I am not sure what I'm doing wrong. Here is my entire User.php file.

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    public function seminar()
    {
        return $this->hasMany('Seminar');
    }

    use UserTrait, RemindableTrait;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password', 'remember_token');

}

Here is an example of another model in the same project

<?php

class Seminar extends Eloquent {

    protected $table = 'seminar';


    public function user()
    {
        return $this->belongsTo('User', 'user_id');
    }
}

I am also using the Sentry Cartalyst package

2
  • And where is your foo function here? If you have question, tell what exactly you do and what error you get for this particular piece of code. Commented Nov 9, 2014 at 10:20
  • 2
    The error almost certainly means that you are trying to call foo on the QueryBuilder object and not your model. This may be due to not calling ->get() (or another function that executes a statement) at the end of your query. If it isn't that show us your "foo" function and how you're calling it. Commented Nov 9, 2014 at 11:51

1 Answer 1

2

I finally realized what the error was. I had a migration that has the same classname (User) and that messed up the User model.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.