R
R
Roman2019-02-15 22:14:18
Laravel
Roman, 2019-02-15 22:14:18

Where in Laravel can you override relationship methods (detach() and toggle())?

Hello.
I want to redefine Laravel methods of working with relationships.
In particular, toggle() and detach() so that they do not delete records from the pivot table, but simply change the flag (an additional field in the same table).
Where is the best place to do this?
And how then to inherit, etc.?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Wells, 2019-02-15
@Alex_Wells

You can do it, but you don't have to. If you want to change the field - create your own relational objects, and override the methods you need as much as you like. Don't touch the default ones.

M
miki131, 2019-02-16
@miki131

Can you make a macro for BelongsToMany

BelongsToMany::macro('softToggle', function () {

});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question