jeudi 9 mars 2017

Send recently saved data from controller to DOM in Laravel

On my website, users can reply to statuses.

$reply = Status::create([
        'body' => $replyText,
    ])->user()->associate(Auth::user());

status->replies()->save($reply);

The request is sent through AJAX. If the request succeeds, the reply is generated automatically on the DOM without a page redirect.

And that's cool and all, but I also want users to be able to delete/edit replies they just made! And for that, I would need the ID in my status table of the newly created reply.

Something like...

$reply = Status::create([
        'body' => $replyText,
    ])->user()->associate(Auth::user());

$status->replies()->save($reply);

$replyID = ID of the status I just saved to database;
return response()->json($replyID);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire