jozenaiser
2 years ago

500 http error - AJAX

Posted 2 years ago by jozenaiser

Hello guys.

I'm having some problems at updating a model via ajax.

If I comment the specific line where I save the model ($tag->save()), no error is thrown, but once I uncomment it, I get that error which has been driving me crazy.

Can somebody help me?

This is the code:

public function edit(Request $request) {

    $this->validate($request, [
        'name' => 'required|max:75',
    ]);
    if($request->ajax()) {
        $tag = Tag::find($request->id);
        $tag->name = $request->name;
        $tag->save();

        if($request->type == 'hashtag') {
            Session::flash('message', 'Se ha actualizado correctamente el hashtag!');   
        }else{
            Session::flash('message', 'Se ha actualizado correctamente la categoria!');
        }
        return response()->json(['status' => 'ok']);
    }else{
        return redirect()->back();
    }
     return response()->json(['status' => 'ok']);

}

Please sign in or create an account to participate in this conversation.