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

104 Views Asked by At

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

1

There are 1 best solutions below

2
On

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

$me = new Translation();
$me->save();

return $me->id;