Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Presmelito's avatar

Laravel Nova: Assoicate current user to the created post

How can I associate the current logged in user who submitted the form to the post that will be created?

Hidden::make('User', 'created_by')->default(function ($request) {
   return $request->user()->id;
}),

Having a hidden field with default user_id value seems hackable. Is there any other way?

0 likes
1 reply
gty's avatar
gty
Best Answer
Level 1

You can owerwrite the boot function in the model and set the user id in the created_by attribute using the auth() helper when creating the model. Or you can create an observer for your model and set the value when creating the model aswell.

1 like

Please or to participate in this conversation.