Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent

Hello , I have a problem using the get function id ( $ user- > id ) . This function instead of inserting the id come back to me, I always returns 1 . I specify that my primary key is not named id but user_id, I already defined in the User model .

What could it be?

Thank's

Last updated 3 years ago.
0

May be use follow code

$user = new User;
$user->name = 'demo';
$user->email = 'test@test.com';
$user->save();
$id_after_insert = $user->id;
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

emanuel83 emanuel83 Joined 12 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.