Skip to content

PHPORM-264: Deprecate Mongo soft deletes trait #3408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/includes/eloquent-models/PlanetSoftDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;
use MongoDB\Laravel\Eloquent\Model;
use MongoDB\Laravel\Eloquent\SoftDeletes;

class Planet extends Model
{
Expand Down
1 change: 1 addition & 0 deletions src/Eloquent/MassPrunable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MongoDB\Laravel\Eloquent;

use Illuminate\Database\Eloquent\MassPrunable as EloquentMassPrunable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Events\ModelsPruned;

use function class_uses_recursive;
Expand Down
1 change: 1 addition & 0 deletions src/Eloquent/SoftDeletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MongoDB\Laravel\Eloquent;

/** @deprecated 6.0.0 in favor of \Illuminate\Database\Eloquent\SoftDeletes */
Copy link
Member

@GromNaN GromNaN Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can trigger a deprecation when the PHP file is loaded.

In the @deprecated annotation, we usually give the version of the deprecation.

Suggested change
/** @deprecated 6.0.0 in favor of \Illuminate\Database\Eloquent\SoftDeletes */
trigger_error(sprintf('Since mongodb/laravel-mongodb:5.5, trait "%s" is deprecated, use "%s" instead.', SoftDeletes::class, \Illuminate\Database\Eloquent\SoftDeletes::class), E_USER_DEPRECATED);
/** @deprecated since mongodb/laravel-mongodb:5.5, use \Illuminate\Database\Eloquent\SoftDeletes instead */

Example of an other deprecation I put in the library:

* @deprecated since mongodb/laravel-mongodb:5.2, use getDatabase() instead
*
* @return Database
*/
public function getMongoDB()
{
trigger_error(sprintf('Since mongodb/laravel-mongodb:5.2, Method "%s()" is deprecated, use "getDatabase()" instead.', __FUNCTION__), E_USER_DEPRECATED);

An other example of deprecating a class in Symfony: https://github.com/symfony/symfony/blob/138109a63e2202674d81f31481da7c6defe4c0ce/src/Symfony/Component/Serializer/CacheWarmer/CompiledClassMetadataCacheWarmer.php#L19

trait SoftDeletes
{
use \Illuminate\Database\Eloquent\SoftDeletes;
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Soft.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use MongoDB\Laravel\Eloquent\Builder;
use MongoDB\Laravel\Eloquent\DocumentModel;
use MongoDB\Laravel\Eloquent\MassPrunable;
use MongoDB\Laravel\Eloquent\SoftDeletes;

/** @property Carbon $deleted_at */
class Soft extends Model
Expand Down
2 changes: 1 addition & 1 deletion tests/Scout/Models/ScoutUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace MongoDB\Laravel\Tests\Scout\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\SQLiteBuilder;
use Illuminate\Support\Facades\Schema;
use Laravel\Scout\Searchable;
use MongoDB\Laravel\Eloquent\SoftDeletes;

use function assert;

Expand Down
Loading