GithubHelp home page GithubHelp logo

mlezcano1985 / laravel-pivot-soft-deletes Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 5.0 14 KB

(DEPRECATED) Soft delete Eloquent pivot models using Laravel SoftDeletes trait

License: MIT License

PHP 100.00%
deprecated deprecated-repo laravel laravel-softdeletes-trait pivot-soft-deletes soft-deletes softdeletes trait

laravel-pivot-soft-deletes's People

Contributors

jono20201 avatar mlezcano1985 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-pivot-soft-deletes's Issues

Doesn't work on sync()

The intermediate pivot table doesn't do soft delete when using sync(). For example(),
public function dept()
{
return $this->belongsToMany('App\Dept', 'user_dept', 'user_id', 'dept_id');
}

User is in many to many relation on Dept. Both User and Dept use SoftDeletes, PivotSoftDeletes;
$user = User::find(1);
$user->dept()->sync([3, 2, 8, 4]); // --> this will attach dept id, 3, 2, 8, 4 to the pivot table for user id 1
$user->dept()->sync([3, 2, 9, 4]); // --> this should put delete_at for dept id 8 and add row with dept id 9 in the pivot table

But after I run it, it instead deleted dept id 8 and add dept id 9 in the pivot table.

Note: I use laravel 5.6

Soft delete has no effect on relations

Maybe I'm misunderstanding what this is for. Lets say an event has a many to many relationship with users. This relation is "attendingUsers".

If I get a user through that relation and then detach it, I see deleted_at is populated in the pivot table. But the issue is when you run that relation again, you still get that user.

$event->attendingUsers->count();
=> 20
>>> $event->attendingUsers->first()->detach();
=> 1
>>> $event->attendingUsers->count();
=> 20

Seem like it would be considerably more useful if the relations would prevent associates with soft deleted relations. Am I missing something?

Typo $deteteAt

$deletedAt is mistyped in methods, detachBelongsToManySoftDelete, and detachPivotSoftDelete

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.