Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

I believe this is designed this way to limit number of SQL queries. If you need to get actual data saved in the database, you need to obtain this record explicitely, just the way you did :)

Last updated 2 years ago.
0

kokokurak said:

I believe this is designed this way to limit number of SQL queries. If you need to get actual data saved in the database, you need to obtain this record explicitely, just the way you did :)

thanks for your reply.

I dig into the source code and take some time thinking about the implementation.

I think it make sense: no way that you can create the record and retrieve its full data in just a sql command.

Last updated 2 years ago.
0

Exactly, INSERT query doesn't return actual row.

Last updated 2 years ago.
0

You can do it like this and get the attributes back

$user = New User;
$user->name = 'John'
$user->email = '[email protected]';
$user->save();

//Now user will have all the attributes from the model, even ones you didn't set.

$new_id = $user->id;
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

wppd wppd Joined 12 Feb 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.

© 2024 Laravel.io - All rights reserved.