Support the ongoing development of Laravel.io →
Database Eloquent Blade

An Owner has many Cars...

And in my blade page I have this...

{{{$car->Owner->name}}}

And that works except that the query is adding...

where 'owners'.'deleted_at' is null

which I don't want.

I've tried variations of...

{{{$car->Owner->withTrashed()->name}}}
{{{$car->Owner()->withTrashed()->name}}}
{{{$car->withTrashed()->Owner->name}}}

None of which work.

What is the correct way?

Thanks!

Last updated 2 years ago.
0

Respectful bump.

I just want to be able to control what queries use the deleted_at column.

Last updated 2 years ago.
0

I'm thinking the answer may be to just disable the automatic soft-deleting and add a scope element to the model.

Last updated 2 years ago.
0

When you call the relationship as a function, it creates a new query builder. So you need to use get() or first() in order to use the results:

$car->owner()->withTrashed()->first()->name

See this section of the docs for more info: http://laravel.com/docs/eloquent#one-to-many

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

neon5 neon5 Joined 21 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.