Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doctrine Behaviors Laravel Package

effiana/doctrine-behaviors

View on GitHub
Deep Wiki
Context7

Soft-Deletable

Entity

<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;

/**
 * [@ORM](https://github.com/ORM)\Entity
 */
class Category implements SoftDeletableInterface
{
    use SoftDeletableTrait;
}

Usage

<?php

/** [@var](https://github.com/var) Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface $category */
$category = new Category();
$entityManager->persist($category);
$entityManager->flush();

// get id for later
$id = $category->getId();

// now remove it
$entityManager->remove($category);
$entityManager->flush();

// entity is still there
$categoryRepository = $entityManager->getRepository(Category::class);
$category = $categoryRepository->findOneById($id);

// but it's "deleted"
var_dump($category->isDeleted()); 
// true

Restore?

<?php

use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;

/** [@var](https://github.com/var) SoftDeletableInterface $category */
$category->restore();

var_dump($category->isDeleted());
// false

// do not forget to call flush method to apply the change
$entityManager->flush();

Delete at Given Time?

<?php

use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;

/** [@var](https://github.com/var) SoftDeletableInterface $category */
$category = new Category();

$entityManager->persist($category);
$entityManager->flush();

// delete it tomorrow
$tomorrowDateTime = (new \DateTime())->modify('+1 day');
$category->setDeletedAt($tomorrowDateTime);

var_dump($category->isDeleted());
// false

// 24 hours later...

// OK, I'm deleted
var_dump($category->isDeleted()); 
// true
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui