Reputation: 104
how do i get the inserted id in laravel 7 ?
if (!User::where('Name', $u['name'])->exists()) {
$user= new User;
$user->key = $u['key'];
$user->Name = $u['name'];
$user->save();
dd($user->id());
}
here is my error
Call to undefined method App\User::id()
Upvotes: 0
Views: 151
Reputation: 301
You dont need the parentheses . You can use user->id only
If you use parentheses laravel searches for a function that is why you get that error.
After save laravel fills the object id parameter and you just need to take it.
Upvotes: 1