vendredi 8 juin 2018

How to display in blade which rows are soft deleted?

I have created a polling system and in the backend (CMS area) I want the ability for admins to be able to remove polls. When an admin removes a poll, it should soft delete the poll. This is working as intended, however I also want to have the ability for the admin to be able to restore a poll. To do this I am displaying all of the polls (including the soft deleted polls) in the admin area.

PollController index() to get all polls

$polls = Poll::withTrashed()->get();

In the blade I want to have two different buttons for each poll. One of restoring and one for deleting but I only want to display 1 button for each poll depending on whether it can be restored or deleted.

To do this, I have put this inside the foreach in the blade:

@if($poll->trashed())
// Restore button
@else
// Delete button
@endif

However the issue is, trashed() keeps returning true for all the polls when only 1 out of the 3 polls I have are actually soft deleted. I am unsure as to why trashed() returns all of these are true?

How would I get this method working correctly? Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire