Simeoni Peraparota
Simeoni Peraparota

Reputation: 299

laravel create to database and get the ID

This is my code

        $input = Input::all();
Admin::create(Input::only('username', 'password', 'mobileNumber', 'firstName', 'lastName'));

how to get the ID or the new created admin raw please?

many thanks

Upvotes: 1

Views: 144

Answers (1)

user2629998
user2629998

Reputation:

The Model::create() method returns an instance of the model, so something like this should work :

$model = Admin::create(...); // create the model

$id = $model->id; // gets the `id` attribute from the model

Upvotes: 3

Related Questions