Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

seekhey86's avatar

Synchronicity issue when deleting model and related records.

Good afternoon everybody, Sorry if this might be a simple question, but coulnd't find a solution anywhere. In a controller, I'm trying to delete a Poll object and all the related Questions elements, then show a view where i expect not to see the deleted poll, but when the view is rendered, the code is there. My code is:

        if ($poll) {
            // PollQuestion::where('poll_id', $poll->id)->delete(); 
		// -- DELETES BUT IS SHOWN IN VIEW
	    // $poll->questions()->delete() 
		// -- DELETES BUT IS SHOWN IN VIEW
            $outcome = $poll->delete();
        }

        // sleep(1); -- DOESN'T HELP EITHER!

        return view('content.polls', [
            'title' => 'Polls',
         ]);

If I refresh the view or check in the database, the deleted poll and the questions are gone, so it appears to be a synchronicity problem.. but I didn't expect that in PHP, especially considering that even a dirty sleep() function didn't solve the issue. In other controllers where I simply delete the model the problem doesn't show. My Laravel version is 7.13.0

May anyone help? thanks in advance!

0 likes
1 reply
laracoft's avatar

@seekhey86

  1. $outcome is not passed to the view.
  2. title has the string value of Polls
  3. What is wrong with your output?
  4. And what do you mean by synchronicity? I have never come across this term before.

Please or to participate in this conversation.