0

I have the following code, what I want is to take specific columns of related tables.

auth()->user()->load(['business', 'passwordSecurity']);
0

1 Answer 1

3

To select only specific columns from a relationship you should be able to do it like this:

auth()->user()->load([
    'business' => function ( $query ) {
        $query->select('id', 'title');
    },
    'passwordSecurity',
]);

Or like this:

auth()->user()->load(['business:id,name', 'passwordSecurity']);

Please note that you have to select IDs and foreign key constraints that are needed to form this relationship.

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

1 Comment

Thanks! its working, the main key was in selecting foreign key along other columns, without foreign key it returns null, my mistake was that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.