简体   繁体   中英

Laravel - Insert post id to another table on publish

When I publish a post using store method in Laravel, I want to insert the id of the publishing post to another table right after. How is this possible?

public function store(Request $request){
    $data = new Data;
    // Add other data
    $data->save();

    // Now you can get the last inserted id
    $last_id = $data->id;

    // Or 
    $last_id_2 = DB::getPdo()->lastInsertId();
    // For that, dont forget to add DB class

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM