Associate BelongsTo relationship
Hello, I'm new to using Filament. Can I ask if this is an acceptable approach when saving records with a relationship based on authenticated user data?
resource: https://gist.github.com/dansingian/d1705d6bb133ffd9fca4aaed7828b5bb
create: https://gist.github.com/dansingian/6a05722006d72d1ed2fed80c4890b063
5 Replies
You can hook this into afterCreate?
https://filamentphp.com/docs/2.x/admin/resources/creating-records#lifecycle-hooks
Something like:
It throws an error before it proceeds on the afterCreate, giving me a "General error: 1364 Field 'account_id' doesn't have a default value".
My table schema has
$table->unsignedBigInteger('account_id');
$table->foreign('account_id')
->references('id')
->on('profiles_accounts')
->onUpdate('NO ACTION')
->onDelete('RESTRICT')
;
Ah sorry I mistook the relationship type.
Hook on to this
https://filamentphp.com/docs/2.x/admin/resources/creating-records#customizing-data-before-saving
Filament
Creating records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
just set
$data['account_id'] = auth()->user()->account->id
?still an error, since my account_id is guarded
@z3d0x btw Thank you!