Avatar ·

How to get the ID of the last inserted record in Laravel Eloquent?

Hello everyone! I just started learning Laravel and encountered a problem. I have a simple user registration form on the site. After the user fills out the form and submits the data, I save it to the database via Eloquent. But I need to get the ID of this new record immediately after saving, for example, to create a user profile or immediately redirect them to a page with this ID.\n\nHere is my current code:\n\n```php\npublic function store(Request $request)\n{\n $user = new User();\n $user->name = $request->input('name');\n $user->email = $request->input('email');\n $user->password = Hash::make($request->input('password'));\n $user->save();\n\n // How do I get the ID of the just inserted record here?\n // I tried $user->id, but it returns null