Skip to content

Tips and Tricks

Craig Smith edited this page Dec 17, 2020 · 2 revisions

Working with Soft-Deletes

You may want to run a query that includes soft deletes, only has soft deletes etc:

  1. In your model add the following scopes (you can name then whatever you want) -- Edit: use the built in Scopes from the library

In your resource file add the following:

    protected static $allowedScopes = [
        'withTrashed',
        'onlyTrashed'
    ];

now your rest request will accept:

  • ?withTrashed || ?withTrashed=1 || ?withTrashed=true : will include any trashed items
  • ?withTrashed=0 || ?withTrashed=false : will NOT include any trashed items (basically normal request)
  • ?onlyTrashed || ?onlyTrashed=1 || ?onlyTrashed=true : will include only trashed items