php - Get id of newly added object by Id (using facade)


I want to get Id of newly added row in database. here is the code:

  public function store(Request $request)
        $me = Translation::save();
        return $me->id;


Translation extends Facade but this code returns error :

Trying to get property of non-object.

any idea? var_dump($me) returns bool(true)

tricky part is that Translation model contains only 1 column - id




You need to create a new object first in order to save it and retrieve its ID.

$me = new Translation();

return $me->id;

People are also looking for solutions to the problem: xpath - PHP How to give block of code a parent node


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.