0

I get the following error while trying to retrieve a array list which we use to load into the view to create a select list.

Error: Call to undefined method Illuminate\Database\Query\Builder::albums

In our controller we are using following:

$albums = \Auth::user()->albums->lists('name', 'id');

And in model Albums.php we are using:

<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Albums
 *
 */
class Albums extends Model
{
    protected $table = 'albums';
}

In in our main file:

public function albums()
{

    return $this->hasMany('App\Models\Albums', 'name', 'id');
}

2 Answers 2

2

The problem is \Auth::user() object does not have albums function

The albums() function must be created in User model class

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

2 Comments

Do you example on how to do that?
\Auth::user() return Auth model object. In config/auth.php, you can config Auth model (User model is default). You should view laravel.com/docs/master/authentication for details
-1

After searching around, i have solved it by adding the following to the User() class.

public function albums() 
{
    return $this->belongsTo('App\Media');
}

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.