Let say I have a table with table structure as following:
Table_A
sid (auto increment, primary)
.... some other column ....
created_at (created using laravel eloquent timestamps() function)
updated_at (same as above)
Then, I created a new column by.
$new_row = new TableA; //TableA is a model created pointing to Table_A
$new_row->col1 = 'Some value';
$new_row->col2 = 'Some other value';
// Some other field
$new_row->save()
Then, right after this section of code,
dd($new_row->sid);
Surprisingly, the output is:
null
However, when I change it to:
dd($new_row->id);
It returns the sid (i.e. the primary key value of the row). Is the name of the primary key always id when I am using auto-increment as my primary key in Laravel Model? Or why am I only getting the value when I use the name id?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire