-2

how do I retrieve the id that was just created in the database, when I press the save button, the data is created, and I want to retrieve the id from that data

this my controller code

$cart= new cart;
        $cart->user_id = $request->user_id;
        $cart>vendor_name = $request->vendor_name;
$cart->save();

I want to retrieve the id of the data just created

misry
  • 341
  • 2
  • 4
  • 14

3 Answers3

1

After saving you can access id like:

$cart->id

This will be the id of the card you have recently created.

Sagar Gautam
  • 9,049
  • 6
  • 53
  • 84
0
$cart= new cart;
        $cart->user_id = $request->user_id;
        $cart>vendor_name = $request->vendor_name;
$cart->save();

$cart->id; //here you still have access to the data and you can access the id like this.

Same thing goes to the user_id and any other field, you can access them like this: $cart-> user_id;

Wale
  • 1,644
  • 15
  • 31
0

All information you cation access by this $cart.after saving this you just

$cart->id (to get id)
$cart->user_id(to get user_id)
albus_severus
  • 3,626
  • 1
  • 13
  • 25