How to check if row is soft-deleted in Eloquent

0 votes

In Laravel 5.1 is there a nice way to check if an eloquent model object has been soft-deleted? I'm not talking about selecting data but once I have the object e.g. Thing::withTrashed()->find($id)

So far the only way I can see is

if ($thing->deleted_at !== null) { ... }

I do not see any relevant method in the API that would allow for example

if ($thing->isDeleted()) { ... }
Nov 23, 2020 in PHP by kartik
• 37,510 points
2,615 views

1 answer to this question.

0 votes

Hello,

Try this:

if ($thing->trashed()) { ... }
answered Nov 23, 2020 by Niroj
• 82,880 points

Related Questions In PHP

0 votes
1 answer

How to check if a string is JSON or not?

Hello @kartik, Use JSON.parse function isJson(str) { ...READ MORE

answered Aug 19, 2020 in PHP by Niroj
• 82,880 points
8,346 views
0 votes
1 answer

How to check if the request is an AJAX request with PHP?

Hello @kartik, Try below code snippet if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) ...READ MORE

answered Oct 29, 2020 in PHP by Niroj
• 82,880 points
11,281 views
0 votes
1 answer

How to check an IP address is within a range of two IPs in PHP?

Hello @kartik, With ip2long() it's easy to convert your addresses ...READ MORE

answered Nov 3, 2020 in PHP by Niroj
• 82,880 points
3,188 views
0 votes
1 answer

How to check if memcache or memcached is installed for PHP?

Hii, You can look at phpinfo() or check ...READ MORE

answered Nov 6, 2020 in PHP by Niroj
• 82,880 points
4,286 views
0 votes
1 answer

Uncaught Error: Bootstrap's JavaScript requires jQuery

Hello @kartik, You have provided wrong order for ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
22,447 views
0 votes
1 answer

How to make Bootstrap popover Appear/Disappear on hover instead of click?

Hello @kartik, Set the trigger option of the popover to hover instead ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
2,973 views
0 votes
1 answer

How to enable Bootstrap tooltip on disabled button?

Hii @kartik, You can wrap the disabled button ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
4,675 views
0 votes
1 answer

Error: cannot call methods on button prior to initialization; attempted to call method 'loading'

Hii @kartik, It's caused by jquery-ui and bootstrap-button ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
5,624 views
0 votes
1 answer

How to check if a string is an email address in PHP?

Hello, Try this without regular expressions: <?php ...READ MORE

answered Nov 3, 2020 in PHP by Niroj
• 82,880 points
3,210 views
0 votes
1 answer

How to check if php session is already started or not?

Hello kartik, Use session_id(), it returns an empty string ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,880 points
5,119 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP