Skip to main content

HasMany: Delete Parent - What Happens with Children?

Premium
10:53

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

TG
Thananjeyan G ✓ Link copied!

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.

PK
Povilas Korop ✓ Link copied!

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

TG
Thananjeyan G ✓ Link copied!

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

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

Thanks

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.