Courses

How to Structure Databases in Laravel

HasMany: Delete Parent - What Happens with Children?

Previous: Database Normalization: 1/2/3 Normal Forms
avatar

Hi Povilas,

I followed your vidoes about softdeletes, it works fine.

Contacts page

@foreach ($contacts as $contact)
	 Name : {{ $contact->name }} <br>
    Mobile : {{ $contact->name }} <br>
    Company : {{ $contact->company->name ?? null }} <br>
@endforeach

I need to show $contact->company->name value even if i deleted. How to solve this ??

Thank you.

avatar

In Controller, Contact::withTrashed('company') from what I remember. Or add withTrashed() when defining the company relationship in Contact model.

avatar

Contact::withTrashed('company') - This method not working.

  • Its working - withTrashed() when defining the company relationship in Contact model.

Thanks

avatar
You can use Markdown
avatar
You can use Markdown