Skip to content
Advertisement

Laravel Varbox how can I extend the Revision model

I’m using Varbox admin panel inside a Laravel project. The HasRevisions trait on my Article custom entity and everything works as expected.

However, recently I’ve extended the revisions database table to also support soft deleting by adding a deleted_at column, but I don’t know how to actually extend the Revision model to support soft deleting.

Can someone please help?

Thanks a lot!

Advertisement

Answer

As with most custom developed functionalities inside Varbox, you have the option of overwriting the bindings.

This means that you can swap the VarboxModelsRevision model with your own implementation and Varbox will take care of using your implementation everywhere.

To overwrite the revision model binding, go to config/varbox/bindings.php and change the value for revision_model:

/*
|
| Concrete implementation for the "revision model".
| To extend or replace this functionality, change the value below with your full "revision model" FQN.
|
| Your class will have to (first option is recommended):
| - extend the "VarboxModelsRevision" class
| - or at least implement the "VarboxContractsRevisionModelContract" interface.
|
| Regardless of the concrete implementation below, you can still use it like:
| - app('revision.model') OR app('VarboxContractsRevisionModelContract')
| - or you could even use your own class as a direct implementation
|
*/

'revision_model' => AppYourRevisionModel::class,

// 'revision_model' => VarboxModelsRevision::class,

Once that’s done, you can write your soft deleting behavior inside your model.

The easiest way to conform with the requirements of the revision model is to extend your own model with the Varbox one, or at least implement the VarboxContractsRevisionModelContract

<?php

namespace App;

use IlluminateDatabaseEloquentSoftDeletes;
use VarboxModelsRevision as VarboxRevisionModel;

class YourRevisionModel extends VarboxRevisionModel
{
     use SoftDeletes;
}

Here’s the documentation part for reference: https://varbox.io/docs/1.x/model-revisions#overwrite-bindings

Also, you might want to learn about overwriting bindings: https://varbox.io/docs/1.x/custom-bindings

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement