Skip to content

Commit

Permalink
[1.x] Clarifies callbacks [skip-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGhostHunter committed Mar 15, 2024
1 parent 87509b4 commit b3e36a3
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,22 @@ return Car::migration(function (Blueprint $table) {
})
```

An end-developer can also add multiple callbacks programmatically if needed, which are great to separate concerns.

```php
use MyVendor\MyPackage\Models\Car;
use Illuminate\Database\Schema\Blueprint;

return Car::migration(
fn ($table) => /* ... */,
fn ($table) => /* ... */,
fn ($table) => /* ... */,
);
```

> [!TIP]
>
> If you don't want to support additional columns, it's fine. If the end-developer adds a callback, it won't be executed regardless.
> You can omit the `addColumns()` call if you don't want to support additional columns, as any added callback won't be executed.
### Morphs

Expand Down Expand Up @@ -234,7 +247,7 @@ return Car::migration()->morph('ulid', 'custom_index_name');

### After Up & Before Down

The `CustomizableMigration` contains two methods, `afterUp()` and `beforeDown()`. The first is executed after the table is created, while the latter is executed before the table is dropped. This allows the developer to run custom logic to enhance its migrations, or avoid failing migrations.
An end-developer can execute logic after the table is created, and before the table is dropped, using the `afterUp()` and `beforeDown()` methods, respectively. This allows the developer to run enhance the table, or avoid failing migrations.

For example, the end-developer can use these methods to create foreign column references, and remove them before dropping the table.

Expand All @@ -251,6 +264,10 @@ return Car::migration()
});
```

> [!IMPORTANT]
>
> The `afterUp()` and `beforeDown()` adds callbacks to the migration, it doesn't replace them.
## Package documentation

If you plan to add this to your package, you may also want to copy-and-paste the [MIGRATIONS.md](MIGRATIONS.md) file in your package. This way developers will know how to use your model and migrations. Alternatively, you may also just copy its contents, or link back to this repository.
Expand Down

0 comments on commit b3e36a3

Please sign in to comment.