Waterhole uses standard Laravel database migrations and Eloquent models.
As with any standard Laravel application, you can generate and run database migrations as needed.
If you're developing an extension, don't forget to load your migrations in your service provider.
Waterhole's Eloquent models are found in the Waterhole\Models
namespace.
To define new relations on Waterhole's models, use the resolveRelationUsing
method, typically in the boot method of a service provider:
use App\Models\Address;
use Waterhole\Models\User;
User::resolveRelationUsing('address', function (User $user) {
return $user->belongsTo(Address::class, 'address_id');
});
You can listen for the standard events dispatched by Eloquent models to hook into the following moments in a model's lifecycle: retrieved
, creating
, created
, updating
, updated
, saving
, saved
, deleting
, deleted
, restoring
, restored
, and replicating
.
use Waterhole\Models\User;
User::created(function (User $user) {
// ...
});
Waterhole models also dispatch an initialized
event whenever a new model instance is constructed. This can be useful if you need to define new attribute casts, or set the default value of an attribute:
use App\Models\Address;
use Waterhole\Models\User;
User::initialized(function (User $user) {
$user->mergeCasts(['subscribed_at' => 'datetime']);
});