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

Snapey's avatar

ok, there you go. You may have accidentally created it, or your update method might not be working right and creating a duplicate instead of editing the original

henryoladj's avatar

@snapey

public function create()
    {
        return view('news.create');
    }
public function update(Request $request, News $news)
    {
        if(auth()->user()->id !== $news->user_id){
            abort(401, "Please Login");
        }

        $this->validate($request,[
            'subject'=>'required|min:10',
            'body' => 'required|min:20'
        ]);

        $news->update($request->all());

        return redirect()->route('news.show', $news->slug)->withMessage('News Updated');
    }

How can i avoid the duplicate content?

Snapey's avatar

That update method is passed the existing news instance which you then update, so it won't be that.

Snapey's avatar

well it depends what you are doing when a duplicate appears? All you have said is that one of the news items is a duplicate.

Did that happen recently? Does it keep happening? Could it have been created when you were developing your code?

Previous

Please or to participate in this conversation.