A
A
akdes2017-06-26 19:56:32
Laravel
akdes, 2017-06-26 19:56:32

Laravel doesn't return id after object creation, why?

Hello.
I'm ready to tear my hair out on my head ->
when creating an object, I need to know the ID, according to my logic MyModel::create($data) should return a freshly created object, but it's not. Maybe it's in the settings?

$location = Location::create(['value' => $value]);
dd($location->id); //NULL

Tell me what am I doing wrong?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
akdes, 2017-06-27
@akdes

I found an error - according to an erroneous design, the ID was String and registered in the model. Now everything has changed, but I forgot one thing: by removing this line I get an ID

A
Alexander Aksentiev, 2017-06-26
@Sanasol

Well, wardump an object first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question