Level 2
I suggest you to try this
$user = User::create(['name'=>'Pardeep']);
$user->id
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
How can I add userID field in the create?
$product = Product::create(request(['name', 'price']));
If you have setup the relation products in the user model, you dont need to set the key at all, Eloquent will do it for you;
$product = $request->user()->products()
->create(request(['name', 'price']));
Please or to participate in this conversation.