call collection with other model to lists

ONYX

How do I call the relational data in the statement below using a with statement.

$suppliers = Supplier::with('user')->lists('user.company', 'user.id'); // doesn't work

class Supplier extends Model
{
    protected $table = "suppliers";

    protected $fillable = ['email'];


    public function user() {
        return $this->belongsTo('App\User', 'email', 'email');
    }
}
Samuele Colombo

You achieve your goal using the pluck method:

Supplier::with('user')->get()->pluck ('user.company', 'user.id');

The get method returns a Collection, then you can use its methods.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Call method inside of other model

From Dev

How to call a function on model Collection laravel

From Dev

Yii Call beforeSave() in other model's to be Save

From Dev

How to call functions in a main view model from other view models?

From Dev

How to call functions in a main view model from other view models?

From Dev

Model collection inside a Model

From Dev

Model collection inside a Model

From Dev

Lists subitems in collection

From Dev

Modify lists defined by other lists

From Dev

Getting model.id from backbone.js collection create success call using Tastypie?

From Dev

Getting model.id from backbone.js collection create success call using Tastypie?

From Dev

lodash filter collection by other collection

From Dev

Mongodb copy a collection into an other collection

From Dev

Will Garbage collection take care of values of lists of lists

From Dev

Why controller action should call one model method other than an initial find or new?

From Dev

Filter Backbone collection into multiple lists

From Dev

Cannot bind model to collection

From Dev

Model Binding to an object with a collection

From Dev

MVC Nested Model Collection

From Dev

Adding model to a collection not working

From Dev

Collection inside a Backbone model

From Dev

ModelBinding on model collection

From Dev

Collection-less model

From Dev

MVC Nested Model Collection

From Dev

Call Method of Collection In Java

From Dev

Python adding lists of numbers with other lists of numbers

From Dev

Simpler Way of Creating Lists from other Lists

From Dev

Python adding lists of numbers with other lists of numbers

From Dev

Laravel - Diference between Model::lists('id') and Model::all()->lists('id')?

Related Related

HotTag

Archive